0

i want to use this script to do ping without using the exec(); or the commands that similar to it.

the problem is i get these errors:

Strict Standards: Non-static method Net_Ping::factory() should not be called statically in C:\xampp\htdocs\test.php on line 3

Strict Standards: Non-static method Net_Ping::_setSystemName() should not be called statically in C:\xampp\php\PEAR\Net\Ping.php on line 141

Strict Standards: Non-static method Net_Ping::_setPingPath() should not be called statically in C:\xampp\php\PEAR\Net\Ping.php on line 143

Strict Standards: Non-static method PEAR::isError() should not be called statically in C:\xampp\htdocs\test.php on line 4

the code on test.php

<?php
require_once "Net/Ping.php";
$ping = Net_Ping::factory();
if (PEAR::isError($ping)) {
    echo $ping->getMessage();
} else {
    $ping->setArgs(array('count' => 2));
    var_dump($ping->ping('example.com'));
}
?>
Eli Y
  • 877
  • 16
  • 41
  • 1
    where's your code, it looks like the error messages are clearly explaining what is wrong. – dm03514 Sep 27 '11 at 13:03
  • the code is here http://pear.php.net/manual/en/package.networking.net-ping.ping.php and i didn't this file C:\xampp\php\PEAR\Net\Ping.php i downloaded this from pear.php – Eli Y Sep 27 '11 at 13:06
  • We need the code from `C:\xampp\htdocs\test.php` – J0HN Sep 27 '11 at 13:24

2 Answers2

3

Nothing wrong, the PEAR component is just not fit for E_STRICT. The code you have is okay, but the PEAR code doesn't say the method is static, so PHP will emit an E_STRICT warning. That's not something you can really change, but you can opt to ignore it, by adjusting your error_reporting settings.

<?php
// before PEAR stuff.
$errLevel = error_reporting( E_ALL );

// PEAR stuff.
require_once "Net/Ping.php";
$ping = Net_Ping::factory();
if (PEAR::isError($ping)) {
    echo $ping->getMessage();
} else {
    $ping->setArgs(array('count' => 2));
    $result = $ping->ping('example.com');
}

// restore the original error level.
error_reporting( $errLevel );
var_dump( $result );
Berry Langerak
  • 18,561
  • 4
  • 45
  • 58
1

Here is a ping class I wrote last year when I needed to do this on a system that didn't have PEAR.

Example usage:

$ping = new ping();
if (!$ping->setHost('google.com')) exit('Could not set host: '.$this->getLastErrorStr());
var_dump($ping->send());
DaveRandom
  • 87,921
  • 11
  • 154
  • 174