dongli564510 2016-09-23 10:58
浏览 230
已采纳

如何使用set_time_limit在N秒后停止php脚本?

I have that simplest possible script:

 <?php
if( ini_get('safe_mode') ){
  echo "safe mode !";
}else{
   echo "NOT safe mode !";
}

set_time_limit(3);

for ($i=0;$i<30;$i++) {
    sleep(1);
    echo $i;
}

I have as output Not safe mode 0123456....

Why does my script does not stop after 3 seconds ?

(I run it in SSH console)

  • 写回答

2条回答 默认 最新

  • doqs8936 2016-09-23 11:02
    关注

    Time spent sleeping doesn't count towards script execution time. From the manual:

    The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码