duanbo7517 2014-03-15 06:22
浏览 43

如何在特定时间后停止在php中执行某个函数?

I have five exec() function in my script, which run one after another. I want exec() function stops its execution after 10 sec and next exec() function starts its execution.

<?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 />";
  }

   .......
  ?>
  • 写回答

1条回答 默认 最新

  • duanlan7239 2014-03-15 06:26
    关注

    set_time_limit() does run globally, but you may be able to set it locally,

    <?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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法