Warning: socket_read() [function.socket-read]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Warning: socket_read() [function.socket-read]

Post by dull1554 »

can anyone shine some light on this?

I have this code to check if an aim user is on line.

Code: Select all

<?php
function aimStatus($sn) {
$port = "80";
$address = "big.oscar.aol.com";

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($socket < 0) echo "error: " . socket_strerror($socket) . "\n";

$result = socket_connect($socket, $address, $port);
if($result < 0) echo "error: " . 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) {
return TRUE;
} elseif (strstr($out, "false")==True) {
return FALSE;
} else {
return FALSE;;
}
}

socket_close($socket);
}
$time_start = microtime(true);
if(aimStatus($_GET['sn']) == TRUE) echo "Online";;
if(aimStatus($_GET['sn']) != TRUE) echo "Offline";;
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<br /><br />Executed in $time seconds\n";
?>
approx. 1/10 executions I recieve this error.

Code: Select all

Warning: socket_read() [function.socket-read]: unable to read from socket [0]: An existing connection was forcibly closed by the remote host. in U:\wwwroot\htdocs\forbidden\aimstatus.php on line 18
anyone know what may cause this?
Post Reply