120秒后504

时间:2018-10-06 12:17:20

标签: php file-get-contents http-status-code-504

我有这个代码

$url="site.com";//~
$opts=array(
    'http'=>array(
        'method'=>"GET",
        'header'=>"Accept: */*i\r\n".
              "User-Agent: Your application name\r\n",
        "ignore_errors" => true,
        "timeout" => 1800
    ),
    "ssl"=>array(
        "allow_self_signed"=>true,
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    )
);
$page = file_get_contents($url, false, stream_context_create($opts));
...
...

如果 $ url (网页)的尺寸很小-脚本运行良好。

但是当尺寸很大并且运行时间开始超过120秒时-

进程将中止并显示504错误。

-

在脚本的开头,我添加:

ini_set('max_execution_time',18000);
ini_set('default_socket_timeout',18000);
ignore_user_abort(true);
ini_set('memory_limit','512M');

ini.php 中,我添加了以下内容:

max_execution_time = 18000;
max_input_time = 18000;

但是没有帮助。

问题:如何延长脚本执行时间-超过120秒?

PS:以上所有内容( max_execution_time ,...)根据指定的标记(如 phpinfo()所示)进行了更改)。但是参数 realpath_cache_size realpath_cache_ttl (写在 phpinfo()中等于120)不变。也许这有问题吗?

1 个答案:

答案 0 :(得分:0)

只要您设置了您的代码,它就会一直运行, 实际上,只要将其添加到代码顶部即可

       set_time_limit(0);

它不会停止直到结束, 但是,如果要一直等待输出,则需要设置Apache2超时限制以及您的浏览器超时限制。