1

当我在 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
4

1 回答 1

0

您可以尝试使用 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);
于 2014-03-02T00:48:07.980 回答