You could send a ping to a host that is probably up (e.g. Google).
There seems to be no PHP built-in for this, so you'd have to resort to shell commands. The return value of ping
on *nix can tell you whether a reply was received.
Update: ping -c1 -q -w1
should be the right command on Linux. This will give you exit code 0 if a reply was received, something else otherwise, and it times out after one second.
Hence, something like this (warning, my PHP is rusty) should do the trick:
function is_online() {
$retval = 0;
system("ping -c1 -q -w1", $retval);
return $retval == 0;
}