我的脚本中有五个exec()函数,它们一个接一个地运行。我希望exec()函数在10秒后停止执行,然后exec()函数开始执行。

<?php
  exec("/usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
  foreach($uptime as $load){
    echo $load."<br />";
  }

  exec("/usr/local/bin/trun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
  foreach($uptime as $load){
    echo $load."<br />";
  }

  exec("/usr/local/bin/drun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$uptime);
  foreach($uptime as $load){
    echo $load."<br />";
  }

   .......
  ?>

最佳答案

set_time_limit()在全局运行,
但你可以在本地设置,

<?php
set_time_limit(0);
function do()
{
    set_time_limit(10);
    //  work
    set_time_limit(10);

}

// ....
sleep(900);
// ....
do();  // only has 10 secs to run
// ....
sleep(900);

10-06 11:09