php exec in the background with WAMP on Windows -


with following code can call php script , pass variables it

$cmd = 'php -f c:/wamp/www/np/myphpscript.php '.$var1;   exec($cmd);  

this way called script works, , need process in background , dont want wait script finish, there way of doing using wamp on windows ? been doing reading , add & @ end of command, or > nul , noticed of them linux , there such command wamp on windows ? if there please share it

edit: due way exec() command waits program finish executing, it's difficult vanilla exec(). came across these solutions, , 1 should work:

$rshell = new com("wscript.shell"); $rexec = $rshell->run("php -f c:/wamp/www/np/myphpscript.php ".$var1, 0, false); 

the wscript.shell->run command takes 3 arguments: command (you can optionally add output redirection), window mode (0 = hidden), , wait should wait finish. because 3rd argument false, php should return immediately.

original solution: this post suggests, should try start /b cmd. virtually linux equivalent of cmd & in runs command asynchronously, in background, without user interaction or opening new shell.

because return immediately, php won't wait finish, , exec() command not receive output. instead, try using shell output redirection. php given code this:

$cmd = 'start /b "" php -f c:/wamp/www/np/myphpscript.php '.$var1.' >c:/wamp/www/np/output.txt'; exec($cmd);  

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -