php - set_time_limit 不影响 PHP-CLI

标签 php

如何解决 set_time_limit 不影响 PHP-CLI?

#!/usr/bin/php -q 
<?php
set_time_limit(2);
sleep(5); // actually, exec() call that takes > 2 seconds
echo "it didn't work again";

最佳答案

max_execution_time限制,这就是set_time_limit设置、计数 (至少在 Linux 上) PHP 进程在工作时花费的时间。

引用 set_time_limit() 的手册页:

Note: 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.

当您使用 sleep() 时,您的 PHP 脚本不工作:它只是在等待...所以 没有考虑您等待的 5 秒max_execution_time 限制。

关于php - set_time_limit 不影响 PHP-CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2635002/

相关文章:

php - 如何使用单个 Laravel 代码实例配置和运行具有各自数据库的多个网站

php - 检测一个单元格中的单个或多个单词

php - Laravel 和 MySQL : Duplicate entry inside loop and error on mass insertion to table

php - 优化大型Mysql数据库

PHP 正则表达式捕获第一个模式及其后的所有内容,即使它重复。

javascript - 在没有 iframe ID 的情况下从表 td 类访问 iframe

php - Google Analytics 导致 500 内部错误

php - 在 Yii 1.x 中以 CHtml 形式输入阿拉伯语并返回未知字符

javascript - Chart js PHP 和 JSON 不会显示

php - 为什么这个 sql 不工作?