sending http requests with curl but closing before reading the response

This is a discussion on sending http requests with curl but closing before reading the response within the PHP Language forums, part of the PHP Programming Forums category; Is it possible to send http requests with curl but not have curl wait for the response? The reason I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-27-2006
yawnmoth
 
Posts: n/a
Default sending http requests with curl but closing before reading the response

Is it possible to send http requests with curl but not have curl wait
for the response?

The reason I ask is because I'd like to code a web app that can sorta
start time consuming processes without the user having to wait. I'm
doing this (with fsockopen) by sending an http request to a page that
does the time consuming stuff and then immediatly closing, without
having read any of the response. This way, I don't have to wait for
the response.

Is it possible to do the same thing with curl? Sending just HEAD
requests doesn't work since it'd seem that the response (which I don't
yet know how to disable, if possible) is only sent at the end of the
pages execution. This might be a mod_gzip issue, but I'd rather use
fsockopen then disable mod_gzip.

Any ideas?

Reply With Quote
  #2 (permalink)  
Old 07-27-2006
Erwin Moller
 
Posts: n/a
Default Re: sending http requests with curl but closing before reading the response

yawnmoth wrote:

> Is it possible to send http requests with curl but not have curl wait
> for the response?
>
> The reason I ask is because I'd like to code a web app that can sorta
> start time consuming processes without the user having to wait. I'm
> doing this (with fsockopen) by sending an http request to a page that
> does the time consuming stuff and then immediatly closing, without
> having read any of the response. This way, I don't have to wait for
> the response.
>
> Is it possible to do the same thing with curl? Sending just HEAD
> requests doesn't work since it'd seem that the response (which I don't
> yet know how to disable, if possible) is only sent at the end of the
> pages execution. This might be a mod_gzip issue, but I'd rather use
> fsockopen then disable mod_gzip.
>
> Any ideas?


Hi yawnmoth,

I think the best approach is to leave CURL and normal tcp/ip interaction
intact. This means: wait for the response.
In that way you actually know that system that performs the calculations is
up and running.

You can however make the heavycalc-script return its response immediately,
and THEN do the calculations.

Maybe someone has a more ellegant solution out there, but this could work:
1) use ob_start() at top of script
2) send a header telling the browser/CURL to go away:
header("Location: bla.html");
where bla.html is a small useless file. Maybe containing only 'doing calc'
or something.
3) flush it to the browser/CURL: ob_flush();

I expect as far as CULR is concerned, the respons ended, but you first
script can now continue doing your calculations.

Do not produce any output from here. Not sure where it goes if you do. :-)

Not tested. I think I solved that problem once like this. But it is quickly
tested by you. Please let us know if it works.

just my 2 cent

Regards,
Erwin Moller
Reply With Quote
  #3 (permalink)  
Old 07-27-2006
yawnmoth
 
Posts: n/a
Default Re: sending http requests with curl but closing before reading the response


Erwin Moller wrote:
> yawnmoth wrote:
>
> <snip>
>
> Hi yawnmoth,
>
> I think the best approach is to leave CURL and normal tcp/ip interaction
> intact. This means: wait for the response.
> In that way you actually know that system that performs the calculations is
> up and running.
>
> You can however make the heavycalc-script return its response immediately,
> and THEN do the calculations.
>
> Maybe someone has a more ellegant solution out there, but this could work:
> 1) use ob_start() at top of script
> 2) send a header telling the browser/CURL to go away:
> header("Location: bla.html");
> where bla.html is a small useless file. Maybe containing only 'doing calc'
> or something.
> 3) flush it to the browser/CURL: ob_flush();
>
> I expect as far as CULR is concerned, the respons ended, but you first
> script can now continue doing your calculations.
>
> Do not produce any output from here. Not sure where it goes if you do. :-)
>
> Not tested. I think I solved that problem once like this. But it is quickly
> tested by you. Please let us know if it works.
>
> just my 2 cent

That's what register_shutdown_function used to do in PHP 4.0.6 and
earlier under Apache. Unforutnately, last time I tried it, it didn't
work with mod_gzip (I had to disable it for that to work).

Reply With Quote
  #4 (permalink)  
Old 07-27-2006
Erwin Moller
 
Posts: n/a
Default Re: sending http requests with curl but closing before reading the response

yawnmoth wrote:

>
> Erwin Moller wrote:
>> yawnmoth wrote:
>>
>> <snip>
>>
>> Hi yawnmoth,
>>
>> I think the best approach is to leave CURL and normal tcp/ip interaction
>> intact. This means: wait for the response.
>> In that way you actually know that system that performs the calculations
>> is up and running.
>>
>> You can however make the heavycalc-script return its response
>> immediately, and THEN do the calculations.
>>
>> Maybe someone has a more ellegant solution out there, but this could
>> work: 1) use ob_start() at top of script
>> 2) send a header telling the browser/CURL to go away:
>> header("Location: bla.html");
>> where bla.html is a small useless file. Maybe containing only 'doing
>> calc' or something.
>> 3) flush it to the browser/CURL: ob_flush();
>>
>> I expect as far as CULR is concerned, the respons ended, but you first
>> script can now continue doing your calculations.
>>
>> Do not produce any output from here. Not sure where it goes if you do.
>> :-)
>>
>> Not tested. I think I solved that problem once like this. But it is
>> quickly tested by you. Please let us know if it works.
>>
>> just my 2 cent

> That's what register_shutdown_function used to do in PHP 4.0.6 and
> earlier under Apache. Unforutnately, last time I tried it, it didn't
> work with mod_gzip (I had to disable it for that to work).


well, did you try it?
Reply With Quote
  #5 (permalink)  
Old 07-27-2006
Andy Hassall
 
Posts: n/a
Default Re: sending http requests with curl but closing before reading the response

On 27 Jul 2006 00:14:10 -0700, "yawnmoth" <terra1024@yahoo.com> wrote:

>Is it possible to send http requests with curl but not have curl wait
>for the response?
>
>The reason I ask is because I'd like to code a web app that can sorta
>start time consuming processes without the user having to wait. I'm
>doing this (with fsockopen) by sending an http request to a page that
>does the time consuming stuff and then immediatly closing, without
>having read any of the response. This way, I don't have to wait for
>the response.
>
>Is it possible to do the same thing with curl? Sending just HEAD
>requests doesn't work since it'd seem that the response (which I don't
>yet know how to disable, if possible) is only sent at the end of the
>pages execution. This might be a mod_gzip issue, but I'd rather use
>fsockopen then disable mod_gzip.


I suppose you could use CURLOPT_TIMEOUT set to a short timeout?

I'm not sure what the scope of CURLOPT_TIMEOUT is - if it's for the transfer
only, and CURLOPT_CONNECTION_TIMEOUT is specifically for the handshaking, then
it ought to fit your purpose.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
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:21 AM.


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