【问题标题】:Heroku PHP - file_get_contents from Heroku Server to itself causes H12 Request TimeoutHeroku PHP - 从 Heroku 服务器到自身的 file_get_contents 导致 H12 请求超时
【发布时间】:2013-11-02 05:27:51
【问题描述】:

当我在 Heroku 上运行的 PHP 代码中向服务器本身发出 HTTP 请求时,我经常收到请求超时 (H12),尽管当我在浏览器中打开请求页面时,它本身运行平稳。我认为这与负载平衡或一台服务器无法处理两个并发请求有关?

有什么办法可以避免这种情况发生吗?

在 myapp.herokuapp.com/site1.php 上运行的伪代码

file_get_contents("myapp.herokuapp.com/site2.php");

在 myapp.herokuapp.com/site2.php 上运行的伪代码

echo "Hello";

日志中的结果:

at=error code=H12 desc="Request timeout" method=GET path=site2.php host=myapp.herokuapp.com fwd="xx.xx.xx.xxx" dyno=web.2 connect=3ms service=30001ms status=503 bytes=0

【问题讨论】:

    标签: php heroku load-balancing file-get-contents http-status-code-503


    【解决方案1】:

    您可以尝试使用 cURL 选项而不是 file_get_contents

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "myapp.herokuapp.com/site2.php"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $temp = trim(curl_exec($ch));
    curl_close($ch);
    

    【讨论】:

      猜你喜欢
      • 2021-06-07
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 2017-07-16
      相关资源
      最近更新 更多