请求不等待PHP长进程,返回503服务不可用

时间:2016-07-21 15:22:44

标签: php apache http

我想通过PHP中的ini_set函数测试max_execution_time设置。所以我设置了一个简单的测试,创建一个无限循环,以确保它会超时。

这是我的代码

Test.php
<?php         
   ini_set('max_execution_time', 300);
   echo "Hello World";
   //for(;;); Commented, see history
   sleep(100);

?>

这个代码在我在顶级XAMPP上运行的Windows机器上运行良好。 5分钟后,它将显示Hello World和超时超时的致命错误。

然后我将代码移动到运行ubuntu和Apache的VPS。然后我从浏览器打开网页。但是,仅在1分钟后,我的浏览器显示

Error Code: 503 Service Unavailable
Network Error 
A communication error occurred: "Operation timed out"
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.

它甚至不等待5分钟。并且它在1分钟后一直出错。但是在我的错误日志中,Apache会在5分钟后写出超过时间的致命错误。

因此,在我看来,请求在PHP脚本实际完成之前被取消。

我在apache2.conf上使用默认设置和其他虚拟主机

apache2.conf (additional only)
<Directory /var/www/mysite.com/public>
    Options FollowSymLinks
    AllowOverride All
</Directory>

mysite.virtualhost.conf

<VirtualHost virtualhost.mysite.com:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerAdmin admin@mysite.com
    ServerName virtualhost.mysite.com
    ServerAlias virtualhost.mysite.com
    DocumentRoot /var/www/mysite.com/public

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Php.ini文件

Php.ini
safe_mode = off
max_execution_time = 1200

那么,我在这里想念什么配置?我认为我的apache配置有问题,但我不知道哪个部分。

更新

在查看进程运行后,运行无限循环的apache进程占用了99%的CPU。为什么会这样?使用strace查看返回此

的过程
write(10, "36.72.135.58 - - [22/Jul/2016:03:15:35 +0700] \"GET /test11.php HTTP/1.1\" 500 211 \"-\" \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\"\n", 198) = 198
times({tms_utime=29996, tms_stime=4, tms_cutime=0, tms_cstime=0}) = 4967918020
gettimeofday({1469132442, 496002}, NULL) = 0
gettimeofday({1469132442, 496046}, NULL) = 0
shutdown(17, SHUT_WR)                   = 0
poll([{fd=17, events=POLLIN}], 1, 2000) = 1 ([{fd=17, revents=POLLIN|POLLHUP}])
read(17, "", 512)                       = 0
close(17)                               = 0
read(5, 0x7fff82f5cf67, 1)              = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1469132442, 496411}, NULL) = 0
accept4(4,  <detached ...>

1 个答案:

答案 0 :(得分:0)

我有这个问题,我解决了增加清漆的first_byte_timeout /etc/varnish/default.vcl默认是根据您的需要改变了60。

相关问题