2016-07-04 161 views
0

我想執行2個腳本:s1s2。必須執行s2s1。 執行s1的時間是2800秒,我需要在s1之後執行s2。我應該把sleep(3000)放在我的php之間,還是第二個在第一個之後自動執行在php中執行shell_exec的命令

我嘗試這樣做:

exec('python s1 '); //time of execution is 2800s 

sleep(3000); // i want to be sure that the first one is finished 

shell_exec('php /home/Parik/s2.php'); 

回答

1

exec手冊頁:

如果程序開始使用此功能,以便它繼續在後臺運行,輸出該程序必須重定向到一個文件或另一個輸出流。否則會導致PHP掛起,直到程序執行結束。

總之,PHP將等待您的python s1命令完成後再繼續。

請注意,3000秒的執行時間絕對會超時,而不會更改ini文件中的默認最大執行時間。見How to increase maximum execution time in php