Re: non-blocking request to a url (via curl or file_get_contents or whatever)...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# jochem@xxxxxxxxxxxxx / 2007-01-20 01:30:55 +0100:
> > I definitely give a hoot about the content returned ... all I want
> > is for the request to go out on the wire and then have my script
> > immediately continue with what it should be doing.
> > 
> > I believe this would require creating a non-blocking connection in
> > some way, but I'm stuck as to the correct way to tackle this. I've
> > been reading about non-blocking sockets/streams etc but I'm just
> > becoming more and more confused really, anyone care to put me out of
> > my misery?
> 
> did more reading, still unsure of the whole thing, this is what I have
> right now:
> 
> 	    $url = array('', 'tbs.tradedoubler.com', '/report?blablablabla');
>             $isSSL = true;
>             $proto = $isSSL ? 'ssl://' : 'http://';
>             $port  = $isSSL ? 443 : 80;
>             $errno = $errstr = null;
>             if ($sock = fsockopen($proto.$url[1], $port, $errno, $errstr, 10)) {
>                 stream_set_blocking($sock, 0);
>                 fwrite($sock, "GET {$url[2]} HTTP/1.0\r\n");
>                 fwrite($sock, "Host: {$url[1]}\r\n");
>                 //fwrite($sock, "Content-length: 0\r\n");
>                 //fwrite($sock, "Accept: */*\r\n");
>                 fwrite($sock, "\r\n");
>                 fclose($sock);
>             }
> 
> does this make any sense, will this work at all?
> would the 10 second timeout [potentially] negate all the hard work?

Yes, you need to wait for the socket to connect, and that's synchronous
in all cases.  I don't know enough about sockets in PHP to help further
here, but if the semantics follows write(2) behavior in C, then what you
have is broken. Non-blocking IO means the fwrite() could return before
it could write all you gave it (it returns how many bytes it's written).


-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux