curl timeout vs socket timeout

This is a discussion on curl timeout vs socket timeout within the PHP General forums, part of the PHP Programming Forums category; Hi, We have two versions of client code, one using curl, and other one using raw sockets via fsockopen(), and ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-28-2008
Ravi Menon
 
Posts: n/a
Default curl timeout vs socket timeout

Hi,

We have two versions of client code, one using curl, and other one
using raw sockets via fsockopen(), and
we use the following code to set the i/o timeouts:

1) curl:

..
..
curl_setopt( $handle, CURLOPT_TIMEOUT, 1 );
..
..
$resp = curl_exec($handle)


2) sockets:

stream_set_timeout( $sock, 1);

Here we use frwrite() and fread() to send the request and read the
response respectively.


In (1), how is the timeout applied - is it:

a) timeout includes the entire curl_exec() call - the combined socket
write() ( to send the request ) and
the read() ( read the response ) calls.

or

b) timeout is independently applied to write() and read() end respectively.

Some of our tests seem to indicate it is (a).


In (2), I am assuming the stream timeout is applied at each i/o call
independently for fwrite() and fread() - I am pretty
much certain on this as this is how it would map to underlying C calls.....


It will be good to get a confirmation on our doubts.

Thanks,
Ravi
Reply With Quote
  #2 (permalink)  
Old 01-28-2008
Jim Lucas
 
Posts: n/a
Default Re: [PHP] curl timeout vs socket timeout

Ravi Menon wrote:
> Hi,
>
> We have two versions of client code, one using curl, and other one
> using raw sockets via fsockopen(), and
> we use the following code to set the i/o timeouts:
>
> 1) curl:
>
> .
> .
> curl_setopt( $handle, CURLOPT_TIMEOUT, 1 );


From the manual
CURLOPT_TIMEOUT
The maximum number of seconds to allow cURL functions to execute.

Notice: "functions", I would take this as the entire process.


> .
> .
> $resp = curl_exec($handle)
>
>
> 2) sockets:
>
> stream_set_timeout( $sock, 1);


From the manual

Set timeout period on a stream

This would tell me that it is on the entire process, not just one
function call like fwrite() or fread().

>
> Here we use frwrite() and fread() to send the request and read the
> response respectively.
>
>
> In (1), how is the timeout applied - is it:
>
> a) timeout includes the entire curl_exec() call - the combined socket
> write() ( to send the request ) and
> the read() ( read the response ) calls.
>
> or


True for both

>
> b) timeout is independently applied to write() and read() end respectively.


False for both

>
> Some of our tests seem to indicate it is (a).
>
>
> In (2), I am assuming the stream timeout is applied at each i/o call
> independently for fwrite() and fread() - I am pretty
> much certain on this as this is how it would map to underlying C calls.....
>
>
> It will be good to get a confirmation on our doubts.
>
> Thanks,
> Ravi
>


This is what I have experienced at least.

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
Reply With Quote
  #3 (permalink)  
Old 01-31-2008
Richard Lynch
 
Posts: n/a
Default Re: [PHP] curl timeout vs socket timeout

On Mon, January 28, 2008 3:56 pm, Ravi Menon wrote:
> 1) curl:
>
> .
> .
> curl_setopt( $handle, CURLOPT_TIMEOUT, 1 );
> .
> .
> $resp = curl_exec($handle)
>
>
> 2) sockets:
>
> stream_set_timeout( $sock, 1);


This is only for AFTER you've already opened up the socket.

If you want a timeout on the opening, the setting is in php.ini, or
you can just use ini_set() right before the fsockopen.

> In (1), how is the timeout applied - is it:
>
> a) timeout includes the entire curl_exec() call - the combined socket
> write() ( to send the request ) and
> the read() ( read the response ) calls.
>
> or
>
> b) timeout is independently applied to write() and read() end
> respectively.
>
> Some of our tests seem to indicate it is (a).


You'd probably have to ask the cURL folks...

> In (2), I am assuming the stream timeout is applied at each i/o call
> independently for fwrite() and fread() - I am pretty
> much certain on this as this is how it would map to underlying C
> calls.....


Almost for sure, it applies to any given fwrite/fread.

Actually, probably at an even lower level, to any given packet
sent/received within an fwrite/fread

> It will be good to get a confirmation on our doubts.


--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:15 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0