Using this simple php function we can detect whether the Internet connection is working or not

if the internet connection is working the following function will return bool value of 1 else return blank

<?php
function check_internet_connection($sCheckHost = 'www.google.com') {
return (bool) @fsockopen($sCheckHost, 80, $iErrno, $sErrStr, 5);
}

$test = check_internet_connection();
print_r($test);
?>