note 31770 deleted from function.fsockopen by irchtml

From: Date: Tue, 17 Feb 2004 14:08:06 +0000
Subject: note 31770 deleted from function.fsockopen by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65280@lists.php.net to get a copy of this message
Note Submitter: Jack@soinsincere.com ---- Here's a snippet that will open a socket connection, send a request and receive the response, even if it's in "chunked" coding: if (!($request=fsockopen('whatever.com',80,$errno,$errstr))) exit($errstr)); else { socket_set_timeout($request,10); fwrite($request,"GET /index.html HTTP/1.1\r\n\r\n"); do $header.=fread($request,1); while (!preg_match('/\r\n\r\n$/',$header)); if (preg_match('/(?i)transfer\-coding:\s+chunked\r\n/',$header)) do { unset($byte); unset($chunk_size); do $byte=fread($request,1); while (preg_match('/[^a-zA-Z0-9]/',$byte)); if (!($chunk_size=fread($request,4))) break; $chunk_size=hexdec($byte.$chunk_size); $response.=fread($request,$chunk_size); } while ($chunk_size); else { $status=socket_get_status($request); $response=fread($request,$status['unread_bytes']); } fclose($request); } exit($response);

« previous php.notes (#65280) next »