Created
June 7, 2016 17:54
-
-
Save bwente/4e4bb74926ad1603a2ee84b9897e813f to your computer and use it in GitHub Desktop.
MODX snippet to ping a site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// [[pingX? &url=`www.google.com` &offline=`site down`]] | |
$url = $modx->getOption('url', $scriptProperties, ''); | |
$offline = $modx->getOption('offline', $scriptProperties, ''); | |
$timeout = $modx->getOption('timeout', $scriptProperties, '30'); | |
$port = $modx->getOption('port', $scriptProperties, '80'); | |
if (!$socket = @fsockopen($url, $port, $errno, $errstr, $timeout)) { | |
// Offline | |
$result = $offline; | |
} else { | |
//Online | |
fclose($socket); | |
} | |
return $result; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment