Logo         Community
The Company
Your Account
Contact Us
Networking With PEAR
Trawl the archives for PHP versions of common networking tools

| A Ping In Time |

Let's start with something basic: pinging a remote host to see if it's "up". PEAR lets you do this via the Net_Ping package, available at http://pear.php.net/package/Net_Ping. This package internally searches for the system's ping binary, and uses it to test the status of the remote host. Take a look at an example which demonstrates it in action:

// include class

// initialize object
$ping = Net_Ping::factory();

// ping host
$result = $ping->ping("example.com");

Pretty simple, this - initialize an object of the class, and then call its ping() method with the name or IP address of the remote host. You can also access individual elements of the response, by calling different methods of the class. Take a look at this variant, which uses built-in class methods to retrieve the total number of bytes sent, the minimum and maximum response time, and the packet TTL.

// include class

// initialize object
$ping = Net_Ping::factory();

// ping host
$result = $ping->ping("example.com");

// print ping results
echo "Target IP: " . $result->getTargetIp() . "\n";
echo "Total bytes sent: " . $result->getBytesTotal() . "\n";
echo "TTL: " . $result->getTTL() . "\n";
echo "Min: " . $result->getMin() . "\n";
echo "Max: " . $result->getMax() . "\n";
echo "Raw data: " . implode("\n", $result->getRawData());

If you're looking to build a nice Web-based interface to the ping command, these methods can come in handy to format the response output. Pay special attention to the getRawData() method, as this returns the raw output of the system's ping command.

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback