Skip to content

Instantly share code, notes, and snippets.

@MarcelloDuarte
Last active August 29, 2015 13:56
Show Gist options
  • Save MarcelloDuarte/9018637 to your computer and use it in GitHub Desktop.
Save MarcelloDuarte/9018637 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
function restart_web($interface) {
passthru("ifconfig $interface down");
passthru("ifconfig $interface up");
sleep(5);
}
function ping($host) {
return (boolean) @fsockopen($host, 80, $errno, $errstr, 10);
}
while(1) {
sleep(2);
if (!ping("www.google.co.uk")) {
echo "Looks like the connection is down. Let me restart it for you...\n";
restart_web("en0");
continue;
}
echo "Looking good\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment