Php shell\u exec未在后台运行?

Php shell\u exec未在后台运行?,php,exec,background-process,shell-exec,Php,Exec,Background Process,Shell Exec,我有下面的代码,它可以完美地执行,但不能像它应该的那样在后台执行?它实际上会停止页面加载,直到它完成,这是不好的 shell_exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2} {$user_info3} &"); 我也试过了 exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {

我有下面的代码,它可以完美地执行,但不能像它应该的那样在后台执行?它实际上会停止页面加载,直到它完成,这是不好的

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

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

&

意味着它将执行,然后让保留页继续运行

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


根据我的经验,exec()的执行通常需要0.2秒。不管你执行什么命令。如果你把睡眠(10);在您的
backg.php
文件中,执行原始页面是否需要更长的10秒钟?@Sietse这将占用backg.php文件的全部长度来执行。。。它的行为更像一个include,而不是应该在后台执行的exec脚本。你可以看看我在这里发布的答案:也许这会有所帮助。这是一个非常古老的答案,但今天我将在2021年使用Apache2和mod_php在后台运行Laravel任务,它不支持dispatchAfterResponse(不运行assync)
exec("/usr/bin/php /path/background.php > /dev/null 2>&1 &");