I use the following script php to schedule task of archive :
$archive_command = 'SchTasks /Create /SC monthly /MO lastday /TN archive'.date('Y_m').' /TR PHP_BINARY." ".$SCRIPT_DIR.archive.php /M * /ST 23:30';
exec("$archive_command 2>&1");
but when execute SchTasks
to recreate the same task it blocks the execution of the php script. How to avoid this blocking ?
Try with this
pclose(popen("$archive_command 2>&1 &", "r"));
UPDATE: I have picked this function from another site :
function bgExec($cmd) {
if(substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
} else {
exec($cmd . " > /dev/null &");
}
}
There is a way to force shell to return immediately by appending ampersand to the command line with popen
:
# ⇓
popen("$archive_command 2>&1 &", "r");
If this is OK with you, fine. If not, let me know. There is another more complicated way to resolve an issue with starting shell in another thread.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.