Suggestions to improve execution time
Posted: Thu Jul 06, 2006 1:09 pm
my code:
my average execution time is around .05-.08 seconds
would this be faster if it used Curl insted of sockets, or how else could this be tweaked to increase speed.
this code will be slightly addapted to update a colum in a large database of AIM users so speed is important as to not tax my server.
Code: Select all
$time_start = microtime(true);
$port = "80";
$address = "big.oscar.aol.com";
$sn = $_GET['sn'];
$status="unknown";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "error, reason: " . socket_strerror($socket) . "\n";
}
$result = socket_connect($socket, $address, $port);
if ($result < 0) {
echo "error, reason: ($result) " . socket_strerror($result) . "\n";
}
$in = "GET /" . $sn . "?on_url=true&off_url=false HTTP/1.0\r\n";
$in .= "Connection: Close\r\n\r\n";
$out = '';
socket_write($socket, $in, strlen($in));
while ($out = socket_read($socket, 2048)) {
if (strstr($out, "true")==True) {
$status="online";
} elseif (strstr($out, "false")==True) {
$status="offline";
} else {
$status="unknown";
}
}
socket_close($socket);
echo $status;
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<br /><br />Executed in $time seconds\n";would this be faster if it used Curl insted of sockets, or how else could this be tweaked to increase speed.
this code will be slightly addapted to update a colum in a large database of AIM users so speed is important as to not tax my server.