function executePing() { // Run a first instance $app = new PHP_Pinger(); // set e-mail destinators with an array $app->setNotificationTo(array('*****@*****.**', '*****@*****.**')); // you can change the subjects preffix $app->setNotificationPreffix('Network Monitoring'); // you can add a signature at the end of the sent e-mail $app->setNotificationSignature('--' . PHP_EOL . 'The Status CRON Notifier'); // now enable notification (available types are: NONE, PROBLEMS, REPORT) $app->enableNotification(NotificationLevel::REPORT); // add hosts to be checked $app->addHost('nicolabricot.com')->addHost('github.com', 443, 'GitHub ‹3')->addHost('help.github.com', 443, 'Help over HTTPS')->addHost('ftp.github.com', 21); // let's go! $app->run(); // An other instance to check some hosts $cat = new PHP_Pinger(); $cat->enableNotification(NotificationLevel::PROBLEMS)->setNotificationTo(array('*****@*****.**'))->addHost('google.fr', 80, 'Google FR')->addHost('www.google.com', 443, 'Google SSL')->addHost('404.google.com')->addHost('example.com', 8080, 'Bad example')->addHost('example.com', 80, 'Good example')->run(); // Callback functions can be also used }
{ echo '<!-- postRun --></ul><!-- /postRun -->', PHP_EOL; } // create a new application $app = new PHP_Pinger(); // add host to be tested /* addHost($host [, $port [, $label]]) * $host: hostname or IP to be checked (google.fr, www.google.fr, 8.8.8.8, ...) * $port: number port used to open the socket - Default value: 80 * $label: sweety name for $host:$port - Default value: $host */ $app->addHost('nicolabricot.com')->addHost('github.com', 443, 'GitHub ‹3')->addHost('help.github.com', 443, 'Help over HTTPS')->addHost('ftp.github.com', 21); // set callbacks (by default nothing is displayed) $app->registerPreRun('myPreRun')->registerCallback('myCallback')->registerPostRun('myPostRun'); /* SECOND EXAMPLE */ $other_example = new PHP_Pinger(); $other_example->addHost('google.fr', 80, 'Google FR')->addHost('www.google.com', 443, 'Google SSL')->addHost('404.google.com')->addHost('example.com', 22, 'SSH example')->registerCallback('myOtherCallback')->addHost('example.com', 80, 'Good example'); // define an other callback function which is executed when pinging a host function myOtherCallback($online, $host, $port, $label) { echo '<tr class="', $online ? 'on' : 'off', '"><td>', $label, '</td>', '<td><code>', $host, ':', $port, '</code></td>', '<td>', $online ? 'online' : '<strong>offline</strong>', '</td></tr>', PHP_EOL; } ?> <!doctype html> <html> <head> <title>Example HTML · PHP Pinger</title> <style> body { width: 700px; margin: auto; padding: 20px 0; font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; } a { color: #005EA5; text-decoration: none; } a:hover, a:active { color: #2E8ACA; border-bottom: 2px solid #2E8ACA; } a:focus, a:active { background-color: #FFBF47; outline: 3px solid #FFBF47; border: none; }