Page 1 of 1

Suggestions to improve execution time

Posted: Thu Jul 06, 2006 1:09 pm
by dull1554
my code:

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";
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.

Posted: Thu Jul 06, 2006 1:10 pm
by dull1554
oh and the code by the way sends a request to big.oscar.aol.com to determine wither or not a aim user is on or off line

Posted: Sat Jul 08, 2006 2:23 pm
by dull1554
allright, i guess im glad no one has any suggestions. i'll fly whit what i got.

Posted: Sat Jul 08, 2006 3:16 pm
by Ollie Saunders
i main reason your code is slightly slower than most is the fact you are making an external connection with another machine. That takes time and speeding it up is outside your control.
my average execution time is around .05-.08 seconds
For a code requesting stuff over the net that's already really good.
would this be faster if it used Curl insted of sockets, or how else could this be tweaked to increase speed.
try slower. leave it as it is.