2012-05-06 46 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

非常感謝您的幫助!讚賞 –