connect_timeout doesn't work

545 views
Skip to first unread message

Dejan Angelov

unread,
Dec 29, 2013, 4:46:21 PM12/29/13
to guz...@googlegroups.com
I need to limit the time spent to connect to some site to 2 sec.
Say that i have this code - http://pastebin.com/mZH46NyJ

It still takes up to 10+ seconds while it throws the exception. I can't see what's wrong?

Michael Stramel

unread,
Dec 29, 2013, 5:10:04 PM12/29/13
to guz...@googlegroups.com
Dejan,

The code seems correct at a glance. Have you tried turning on the debug flag in the  request options? That should provide you more information on what is going on.
http://docs.guzzlephp.org/en/latest/http-client/client.html#debug

Michael Dowling

unread,
Dec 29, 2013, 5:19:12 PM12/29/13
to guz...@googlegroups.com
Can you make sure you're using the latest version? I remember there being an issue with an earlier version.

-Michael
--
You received this message because you are subscribed to the Google Groups "Guzzle - PHP HTTP client and REST client framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guzzle+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dejan Angelov

unread,
Dec 29, 2013, 5:21:45 PM12/29/13
to guz...@googlegroups.com
This is the output i'm getting: http://pastebin.com/E3fdyh3M
As you can see, it took 16 seconds, and the options are ['connect_timeout' => 2, 'timeout' => 3, 'debug' => true]

Dejan Angelov

unread,
Dec 29, 2013, 5:32:20 PM12/29/13
to guz...@googlegroups.com
Yes, its the latest.

Michael Stramel

unread,
Dec 29, 2013, 5:39:57 PM12/29/13
to guz...@googlegroups.com
You may want to check the URL that you are using as the one in your pastebin doesn't correlate to any website.

Dejan Angelov

unread,
Dec 29, 2013, 5:43:51 PM12/29/13
to guz...@googlegroups.com
That's why i needed the option.. I need to check if the url takes too long to respond (like the url in the pastebin), to ignore it.

Igor Pellegrini

unread,
Sep 1, 2014, 11:05:02 AM9/1/14
to guz...@googlegroups.com
I had the same problem.
And cause of the Framework I'm using I couldn't catch the Exception directly. The namespace was wrong.
I just added a backslash before into

catch (\Exception $err)

and it got the right Exception!
Maybe the cause was that the CurlException's parent is RequestException, that has itself \RuntimeException as parent.
So if you want to catch the parent Exception you need to add the backslash as well.

Don't ask me a deep explanation of that. I'm just supposing.
And probably you already solved the error after so many months ;)
Reply all
Reply to author
Forward
0 new messages