2

I am having an http request and I am using "Httpful Request" to send it in PHP. I am setting a timeout of 20 seconds also in the request as follows:

$req = Request::get($Url);
$response = $req->timeoutIn(20)->expectsHtml()->send();

I was expecting to get an exception after timeout happens and I can handle the exception. But I am getting the following php Fatal error. Why is it so?

PHP Fatal error: Maximum execution time of 30 seconds exceeded in phar://C:/CapPortal/cpPortal/source/wordpress/httpful.phar/Httpful/Request.php on line 202

yivi
  • 23,845
  • 12
  • 64
  • 89
Stanly
  • 547
  • 1
  • 5
  • 22
  • Could be that you're doing something that's 11 seconds long and then waiting for another 19 seconds before PHP gives up. If you set a `timeoutIn(1)` would that work? – apokryfos Feb 22 '17 at 13:48
  • What you pointed out is correct. As @robske_110 told, set_time_limit(30) just before my request solved the issue. – Stanly Feb 22 '17 at 14:12

2 Answers2

3

You can use set_time_limit($seconds) to set that limit higher, if you need more execution time. You can also set it to 0, which means infinite. Warning: Apache (if you're using php with it) may also limit php's execution time.

robske_110
  • 128
  • 7
  • I don't want to change the php time limit. I am giving a timeout in my request to catch the exception before php max execution time reaches. – Stanly Feb 22 '17 at 13:37
  • 1
    I added set_time_limit(30) just before my request solved the issue. Thanks. – Stanly Feb 22 '17 at 14:13
0

The httpful module, itself has some method to set time out name is timeoutIn(). So you can add this method to your code and set the time out, for example to 50 seconds:

$response = $req->timeoutIn(20)->expectsHtml()->timeoutIn(50)->send();

It work fine for me.

shgnInc
  • 1,591
  • 1
  • 17
  • 31