php linux 计时器,Linux上PHP的真实max_execution_time

According to the documentation:

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.

测试证实了这一点:

不会超时

set_time_limit(5);

$sql = mysqli_connect('localhost','root','root','mysql');

$query = "SELECT SLEEP(10) FROM mysql.user;";

$sql->query($query) or die($query.'
'.$sql->error);

echo "You got the page";

会超时吗?

set_time_limit(5);

while (true) {

// do nothing

}

echo "You got the page";

我们的问题是,我们真的希望PHP在给定的时间之后暂停,无论它在做什么(因为如果我们知道我们无法以可接受的数量提供页面,我们不想让资源保持忙碌时间,如10秒).我们知道我们可以使用诸如MySQL wait_timeout之类的设置来进行SQL查询,但页面超时将取决于执行的查询数.

有些人试图提出workarounds,但似乎没有实现.

问:有没有一种简单的方法可以在Linux上获得真正的PHP max_execution_time,或者我们是否更好地在其他地方超时,例如Apache级别?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值