Search code examples
phpexecbackground-processshell-exec

shell_exec not running in background?


I have the following which executes perfectly but NOT in the background as it should? It actually stops the page loading until it finishes which is not good.

shell_exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$user_info3} &");

I also tried

exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$user_info3} &");

I thought the

&

meant it would execute then let the holding page carry on regardless?


Solution

  • exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
    

    php execute a background process

    exec("/usr/bin/php /path/background.php > /dev/null 2>&1 &");