【问题标题】:Guzzle 6 fopen error after 120 secondds120 秒后 Guzzle 6 fopen 错误
【发布时间】:2016-08-26 16:52:14
【问题描述】:

我在 php 中有一个脚本,它使用 Guzzle 6 向这样的 API 发出很长的 GET 请求:

$client = new Client(['base_uri' => $this->app_config["domains"][$this->service_name]);
$response = $client->request('GET', $uri);
return \GuzzleHttp\json_decode($response->getBody(), true);

我想当请愿达到大约 120 秒时问题就来了。错误说:

Error creating resource: [message] fopen(.......): failed to open stream: HTTP request failed! 
[file] /vagrant/Orchestrator/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
[line] 312

我在 php 5.6 和 php.ini 配置为 max_execution_time = 0 的 vagrant box 中启动此脚本。

事实是,在我的本地机器上使用相同的 php.ini 和 php 版本它可以工作。

【问题讨论】:

    标签: php vagrant php-ini guzzle6


    【解决方案1】:

    您的 Vagrant box 似乎无法连接到主机。并且 120 秒是默认超时(检查 PHP 设置中的 default_socket_timeout 值)。

    因此,请检查从 Vagrant 框与外部世界的连接。

    【讨论】:

    • 最终更改 default_socket_timeout 并设置 allow_url_fopen = 1 insted of "On" 似乎可以解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 2018-04-27
    • 2020-05-08
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多