Skip to content

Instantly share code, notes, and snippets.

@bwente
Created June 7, 2016 17:54
Show Gist options
  • Save bwente/4e4bb74926ad1603a2ee84b9897e813f to your computer and use it in GitHub Desktop.
Save bwente/4e4bb74926ad1603a2ee84b9897e813f to your computer and use it in GitHub Desktop.
MODX snippet to ping a site
<?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