set_time_limit 不起作用

visitor 填了表格,提交后(我的php程序要进行一些网络查询,执行时间不可定),如果一段时间没看到结果页面,把页面关闭了,但是我不想php程序退出运行,怎么办?

<?php
set_time_limit(10);
sleep(15);
echo "test";
?>

结果浏览器一段时间后,显示了 test。难道是 set_time_limit 不起作用? 百度搜:set_time_limit 不起作用,找到很多资料,都说 set_time_limit 在windows下不起作用,只有通过修改 php.ini 里的 max_execution_time 的值 来控制执行时间。可我的空间是 linux 系统。

找到  http://blog.csdn.net/mengxiangbaidu/article/details/7305536

http://houbolin.cn/blog/2009/12/31/php-set_time_limit-%E5%92%8C-sleep/

Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of thescript 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. isnot included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

<?php
set_time_limit(40);
while (1) { echo "1"; }
echo "test";
?>
Fatal error: Maximum execution time of 40 seconds exceeded in D:\www\2.php on line 3

这个显示windows下 set_time_limit 也是起作用的吧。

----------------

测试下 max_execution_time 对 php网络函数的影响

a.php

<?php  sleep(50); echo "test2";  ?>

b.php

<?php
set_time_limit(10); $url = "http://xxx/a.php";
$ch = curl_init($url); $html = '';
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);
echo "test1 ". $html;
?>

结果浏览器显示: test1 。说明网络函数在等待数据的时间,是不计入 max_execution_time 的

----------------

a.php

<?php  sleep(400); echo "test2";  ?>

不是说apache 有个timeout值是300,可是执行a.php后,浏览器还是显示了 test2。 不解。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值