Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

Thanks in advance...

like image 387
William Lepinski Avatar asked Dec 10 '12 13:12

William Lepinski


People also ask

Does heroku Support PHP?

Supported versionsHeroku's PHP support extends to applications using the latest available releases in the PHP 7.4, PHP 8.0 and PHP 8.1 series.

What version of PHP does heroku use?

Confirm that your app uses one of the following supported Heroku buildpacks: PHP 5.6 - 7.3 in cedar-14. PHP 5.6 - 7.4 in heroku-16. PHP 7.1 - 8.0 in heroku-18.


1 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?

like image 87
darryn.ten Avatar answered Oct 05 '22 23:10

darryn.ten