Home » Php » Heroku – Timeout on cURL (PHP)

Heroku – Timeout on cURL (PHP)

Posted by: admin July 12, 2020 Leave a comment


I’m trying to create a API proxy for my application but I’m getting some strange timeout erros on 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= 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 />";
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?

Thanks in advance…

How to&Answers:

Try setting a timeout on your cUrl request like so

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. Can you open the resource in your browser?