purplepixie/php-ping
Composer 安装命令:
composer require purplepixie/php-ping
包简介
PHP ICMP/Ping Network Client
README 文档
README
PPPing, the Purplepixie PHP Ping Library is a low-level socket based ICMP ping library written by David Cutting for use within the FreeNATS Network Monitor but now spun out as a standalone library.
Obtaining PPPing
The easiest option is to use composer to be able to obtain the latest package via Packagist with the command:
composer require purplepixie/php-ping
Using composer you can then autoload the classes as needed.
You can also download the source directly (from a tagged release or clone the repo) and include the file src/PurplePixie/PhpPing/PPPing.php.
Note the PPPing class is in the namespace \PurplePixie\PhpPing\PPPing.
Using PPPing
Once included it's very simple to use PPPing.
use \PurplePixie\PhpPing\PPPing; $ping = new PPPing(); // instantiate a PPPing object $ping->setHostname("www.google.com"); // host to ping (hostname or IP) $result=$ping->Ping(); // perform a single ICMP ping // Result is either a negative number (error) or 0 up which is return in ms if ($result<0) // error echo "Error: ".$ping->strError($result)."\n"; else echo "Return: ".$result." ms\n";
Additional Information Available
Following a ping information about the last result is available via PPPing::getLast() which is an associative array with keys as follows:
- set - boolean indicating if data was returned or not
- result - the result value of the ping (negative number means error, 0 or positive is return time in ms)
- ttl - the TTL of the returned packet
- hops - an estimation of the hops based on socket TTL and returned TTL (not always accurate)
- source - IP address of the return packet source (the remote system)
- destination - IP address of the destination of the return packet (local system)
Other Options and Variables
Various options can be read and set as needed within the PPPing object
PPPing::getHostname()gets the remote hostname or IPPPPing::setHostname($host)sets the remote hostname or IPPPPing::getTTL()gets the TTLPPPing::setTTL($ttl)sets the TTLPPPing::getTimeout()gets the Timeout (seconds)PPPing::setTimeout($timeout)sets the Timeout (seconds)PPPing::getPackage()gets the packet package (defaults to "PPPing")PPPing::setPackage($package)sets the packet packagePPPing::getDebug()gets the debug status flag (boolean)PPPing::setDebug($d)sets the debug status flag (boolean)PPPing::getSequence()gets the sequencePPPing::setSequence($s)sets the sequencePPPing::getIdentity()gets the identity usedPPPing::getLast()gets the data about the last ping
Example CLI Implementation
In the bin folder is a ping.php which can be run on the command-line to demonstrate the functionality of PPPing. Options to the ping.php script are:
Usage: php ping.php [options] hostname
Options available are as follows:
--ttl x | -t x Set TTL (not working with ppping yet)
--debug | -d Turn on debug mode and output
--delay x Minimum delay between pings in seconds (or decimal)
--help | -h Display this help and quit
--count x | -c x Number of times to ping (default infinity)
hostname must be a resolvable host or an IP address to ping (required)
purplepixie/php-ping 适用场景与选型建议
purplepixie/php-ping 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 152 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 purplepixie/php-ping 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 purplepixie/php-ping 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 152
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2023-11-07