简体   繁体   English

用php phar ping

[英]ping with php phar

i want to use this script to do ping without using the exec(); 我想使用此脚本来执行ping而不使用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 严格标准:不应在第3行的C:\\ xampp \\ htdocs \\ test.php中静态调用非静态方法Net_Ping :: factory()

Strict Standards: Non-static method Net_Ping::_setSystemName() should not be called statically in C:\\xampp\\php\\PEAR\\Net\\Ping.php on line 141 严格标准:非静态方法Net_Ping :: _ setSystemName()不应在141行的C:\\ xampp \\ php \\ PEAR \\ Net \\ Ping.php中静态调用

Strict Standards: Non-static method Net_Ping::_setPingPath() should not be called statically in C:\\xampp\\php\\PEAR\\Net\\Ping.php on line 143 严格标准:不应在第143行的C:\\ xampp \\ php \\ PEAR \\ Net \\ Ping.php中静态调用Net_Ping :: _ setPingPath()非静态方法

Strict Standards: Non-static method PEAR::isError() should not be called statically in C:\\xampp\\htdocs\\test.php on line 4 严格标准:不应在第4行的C:\\ xampp \\ htdocs \\ test.php中静态调用非静态方法PEAR :: isError()

the code on test.php 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'));
}
?>

Nothing wrong, the PEAR component is just not fit for E_STRICT. 没错,PEAR组件不适合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. 您拥有的代码还可以,但是PEAR代码没有说该方法是静态的,因此PHP将发出E_STRICT警告。 That's not something you can really change, but you can opt to ignore it, by adjusting your error_reporting settings. 这不是您真正可以更改的东西,但是您可以通过调整error_reporting设置选择忽略它。

<?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 );

Here is a ping class I wrote last year when I needed to do this on a system that didn't have PEAR. 是我去年在不需要PEAR的系统上进行此操作时编写的ping类。

Example usage: 用法示例:

$ping = new ping();
if (!$ping->setHost('google.com')) exit('Could not set host: '.$this->getLastErrorStr());
var_dump($ping->send());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM