When using the code below the socket_set_timeout variable lags the loading of the page. Is there anyway to get around this? I've tried setting it to 0, taking the code away and setting the time like 0, 500 to have it in microseconds.. nothing works.. The lowest you can set and make the code still work is to 1 and it still lags a bit.
<?php
set_time_limit( 5 );
$sock = fsockopen( "blab.com", 80, $errno, $errstr, 5 );
if ( ! $sock )
die( "failed to connect" );
fwrite( $sock, "GET /stuff.php HTTP/1.1\r\n" );
fwrite( $sock, "Host: blab.com\r\n\r\n" );
socket_set_timeout( $sock, 1);
// trim the newline
$val = explode( "\n", fread( $sock, 4096 ) );
$found = false;
foreach ( $val as $valp )
if ( preg_match( "/People on ftp:\s(\d+)/", $valp, $match ) )
{
$found = true;
break;
}
if ( !$found )
{
// do error handling here
die;
}
$peopleonftp = $match[1];
if ( $peopleonftp < 45 )
print "The ftp is currently not full - $peopleonftp on the ftp";
else
print "The ftp server is currently full! - $peopleonftp on the ftp";
fclose( $sock );
?>
Thanks,
RogeR