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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改