Using fsockopen

Hi, I’m creating a little server status checker, and looks like the following:
[php]<?php
header(‘Content-type: image/png’);
$socket = @fsockopen(‘http://www.google.com’);
if($socket) {
fclose($socket);
readfile(‘on.png’);
exit;
} else {
readfile(‘off.png’);
exit;
}
?>[/php]

The above returns the “off.png” image all the time. Of course, this script will be using my own IP, but I used google because I was sure it would return the “on.png” image, but it didn’t.

Could anyone point out what I’m doing wrong? I literally fumbled though those few lines and it seems I can’t get it to work.

Dont include http:// in the URI.

The function only supports tcp:// or udp://
Use :-
[php]
$socket = fsockopen(“www.google.com” , 80 , $errno, $errstr);
echo $errno . “\n” . $errstr;
[/php]

I hope it works now

If it still doesn’t works post the output here

Warning: fsockopen() [function.fsockopen]: unable to connect to www.google.com:80 (Unknown error) in /www/110mb.com/v/i/n/d/i/c/a/t/vindicator209/htdocs/derp.php on line 2 -1212492552

Hm… Perhaps it is due to the webhost I’m using?

Sponsor our Newsletter | Privacy Policy | Terms of Service