Skip to content

Instantly share code, notes, and snippets.

@vmosoti
Last active December 19, 2017 13:36
Show Gist options
  • Save vmosoti/7a71011622eecbc5831c1ecb4cebdff1 to your computer and use it in GitHub Desktop.
Save vmosoti/7a71011622eecbc5831c1ecb4cebdff1 to your computer and use it in GitHub Desktop.
Check if Server is Connected to Internet
<?php
function is_connected()
{
$connected = @fsockopen("www.example.com", 80);
//website, port (try 80 or 443)
if ($connected){
$is_conn = true; //action when connected
fclose($connected);
}else{
$is_conn = false; //action in connection failure
}
return $is_conn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment