1

当我在运行在Heroku上的PHP代码中向服务器本身发出HTTP请求时,我经常会收到Request Timeout(H12),虽然请求页面本身当我在浏览器中打开它时,它可以平稳运行。我认为这与负载均衡或一个服务器无法处理两个并发请求有关?Heroku PHP - 从Heroku服务器到它自己的file_get_contents导致H12请求超时

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

在日志上myapp.herokuapp.com/site2.php

echo "Hello"; 

结果运行myapp.herokuapp.com/site1.php

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

伪代码运行的伪代码:

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 

回答

0

你可以尝试使用卷曲选项,而不是的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); 
相关问题