Re: non-blocking request to a url (via curl or file_get_contents or whatever)...
| From: | Jochem Maas | Date: | Sat, 20 Jan 2007 00:30:55 +0000 |
| Subject: | Re: non-blocking request to a url (via curl or file_get_contents or whatever)... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247431@lists.php.net to get a copy of this message | ||
because I like talking to myself :-P ....
Jochem Maas wrote:
> hi,
>
...
> 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?
>
> rgds,
> Jochem
>