简体   繁体   English

Heroku - cURL超时(PHP)

[英]Heroku - Timeout on cURL (PHP)

I'm trying to create a API proxy for my application but I'm getting some strange timeout erros on Heroku. 我正在尝试为我的应用程序创建一个API代理,但我在Heroku上遇到了一些奇怪的超时错误。

The said the following: 说了以下:

2012-12-10T12:49:24+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path=/api/v1/users/me host=host.herokuapp.com fwd=174.129.79.221 dyno=web.1 queue= wait= connect= service=30000ms status=503 bytes=0

The code is something like the following: 代码如下所示:

$request = curl_init();
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_USERAGENT, 'AppProxy/1.0');
curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'Accept: application/json',
    'Authorization: Basic ' . $authorization,
    'X-Requested-With: XMLHttpRequest'
));
curl_setopt($request, CURLOPT_VERBOSE, 1);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($request);
echo curl_errno($request) . "<br />";
echo curl_error($request) . "<br />";
echo $httpStatus = curl_getinfo($request, CURLINFO_HTTP_CODE) . "<br />";
curl_close($request);
echo $response . "<br />";

There's something wrong or I'm missing something on the code to get this working? 有什么问题或者我在代码上遗漏了一些东西以使其工作? Anyone had the same issue on Heroku? Heroku上有人有同样的问题吗?

Thanks in advance... 提前致谢...

Try setting a timeout on your cUrl request like so 尝试在cUrl请求上设置超时,如下所示

curl_setopt($request, CURLOPT_CONNECTTIMEOUT, 15);

How long does it take to wget the same resource from the box it is running on? 从运行它的盒子中获取相同的资源需要多长时间?

Also code 503 is a Service Unavailable error. 代码503也是服务不可用错误。 Can you open the resource in your browser? 你能在浏览器中打开资源吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM