2012-05-06 43 views
3

我有以下完美执行但不在背景中,因为它应该?它实际上停止了页面加载直到完成,这是不好的。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} {$user_info2} {$user_info3} &"); 

我认为

&

意味着它会执行,然后让持有页面进行不分?

+0

在我的经验研究的exec()总是喜欢0.2秒执行。无论你执行什么命令。如果你睡觉(10);在你的'backg.php'文件中,执行原始页面需要10秒钟吗? – Sietse

+0

@Sietse这是采取全长的backg.php文件执行......其行为更像一个包括,而不是一个执行脚本,应该在后台执行 –

+0

你可以看看我的回答我发布这里:http://stackoverflow.com/questions/7703278/grab-results-from-a-php-exec-while-the-command-is-still-running/7703323#7703323也许这可以帮助。 – Sietse

回答

6
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 &"); 
+0

非常感谢您的帮助!赞赏 –