dongya6395 2016-09-18 11:00
浏览 78

php7超时未强制执行

I've been searching for why for the past 2 days and I tried a lot of solutions on the internet and here on stack.

I have a dedicated VM with ubuntu 16.04 with apache2 -> Server version: Apache/2.4.18 (Ubuntu) with the default php instalation: php -v

PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS ).

phpinfo()

PHP Version 7.0.8-0ubuntu0.16.04.2

Recently I noticed that the scripts can run for forever, there is no timeout limit enforced.

I did a phpinfo() to get the php.ini file used. I checked inside the php.ini the following parameters:

default_socket_timeout = 60
session.gc_maxlifetime = 1440
max_execution_time = 30
max_input_time = 60

I even set them to 3 seconds (max_execution_time, max_input_time and default_socket_timeout), restarted apache, but with no results.

The following code for example (and it's not the only one i tried) doesn't time out, it runs until it finishes:

echo "<br>initial max_execution_time: " . ini_get('max_execution_time') ;
print_r(set_time_limit(2));
echo " - set_time_limit
";
echo "<br>initial max_execution_time: " . ini_get('max_execution_time') ;
ini_set('max_execution_time', '1');
echo "<br>initial max_execution_time: " . ini_get('max_execution_time') ;
ini_set('default_socket_timeout','1');
echo "<br>ini_get('default_socket_timeout')". ini_get('default_socket_timeout');
//phpinfo();


set_time_limit(1);
$i = 0;
while(++$i < 1000000001){
        if($i % 100000 == 0){
                echo $i / 100000, "<br/>
";
        }
}
echo "done.<br/>
";

The output is telling me that the timeouts are correctly set, but like I said, the script is running for 32seconds without being killed.

Any ideas why the timeouts are not applied?

Thanks

  • 写回答

1条回答 默认 最新

  • duangua5308 2018-10-05 21:55
    关注

    max_execution_time does not necessarily translate to how long the http request will take. There are other processes that can be run by your php script that will not get counted as execution time. For example, if you run a large database query, the time it takes will not count toward the max_execution_time. In these cases, it is the apache timeout that will be enforced. On ubuntu, your apache2.conf file should contain a line with:

    Timeout 300 
    

    This will be the actual limit that includes the time it takes for all database queries, curl requests, exec calls and other external processes.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀