Example #1
0
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
}
Example #2
0
<?php

// load PHP Pinger
require '../phppinger.class.php';
/* callbacks for example */
function callback($is_online, $hostname, $port, $sweety_name)
{
    echo '<li>', $hostname, ':', $port, ' is ', $is_online ? 'online' : 'offline', '</li>';
}
function preRun()
{
    echo '<ul>', PHP_EOL;
}
function postRun()
{
    echo '</ul>', PHP_EOL;
}
/* instanciate a new Pinger and run it with callbacks and notifications */
$ping = new PHP_Pinger();
$ping->registerCallback('callback')->registerPreRun('preRun')->registerPostRun('postRun')->addHost('nicolabricot.com')->addHost('blog.nicolabricot.com', 80)->addHost('ftp.github.com', 21, 'GitHub FTP')->setNotificationTo(array('*****@*****.**', '*****@*****.**'))->setNotificationPreffix('Network Monitoring')->setNotificationSignature('--' . PHP_EOL . 'By PHP Pinger')->enableNotification(NotificationLevel::REPORT)->run();
Example #3
0
function myPostRun()
{
    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 &lsaquo;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 &middot; 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; }