在php中执行shell_exec的命令
问题描述:
我想执行2个脚本:s1
和s2
。必须执行s2
后s1
。 执行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');
答
从exec手册页:
如果程序开始使用此功能,以便它继续在后台运行,输出该程序必须重定向到一个文件或另一个输出流。否则会导致PHP挂起,直到程序执行结束。
总之,PHP将等待您的python s1
命令完成后再继续。
请注意,3000秒的执行时间绝对会超时,而不会更改ini文件中的默认最大执行时间。见How to increase maximum execution time in php。