<?php

/*
 * Header
 */
$out "GET / HTTP/1.1\r\n";
$out .= "Host: www.google.com\r\n";
$out .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b5) Gecko/2008032620 Firefox/3.0b5\r\n";
$out .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
$out .= "Accept-Language: en-us,en;q=0.5\r\n";
$out .= "Accept-Encoding: gzip,deflate\r\n";
$out .= "Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7\r\n";
$out .= "Keep-Alive: 300\r\n";
$out .= "Connection: keep-alive\r\n\r\n";

/*
 * cURL
 */
$memory memory_get_usage();
$time microtime(true);

$curl curl_init();
curl_setopt($curlCURLOPT_URL"http://www.google.com");
curl_setopt($curlCURLOPT_HEADERfalse);
curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
curl_exec($curl);
curl_close($curl);

$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"cURL took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * fsockopen()
 */
$memory memory_get_usage();
$time microtime(true);

$fsock fsockopen("www.google.com"80);
fwrite($fsock$out);
fread($fsock1024);
fclose($fsock);

$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"fsockopen() took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * fopen()
 */
$memory memory_get_usage();
$time microtime(true);

$fsock fopen("http://www.google.com""r");
fwrite($fsock$out);
fread($fsock1024);
fclose($fsock);

$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"fopen() took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

/*
 * stream_socket_client()
 */
$memory memory_get_usage();
$time microtime(true);

$fsock stream_socket_client("tcp://www.google.com:80");
fwrite($fsock$out);
fread($fsock1024);
//stream_get_contents($fsock);
fclose($fsock);

$time microtime(true) - $time;
$memory memory_get_usage() - $memory;
echo 
"stream_socket_client() took:\t"$time ." & "$memory/1028 ."Kb of memory\n";

?>