drewlabs / net
网络工具库
v0.2.2
2023-06-11 20:46 UTC
Requires
- php: >=7.0
- ext-sockets: *
Requires (Dev)
- phpunit/phpunit: >=6.0
This package is auto-updated.
Last update: 2024-09-11 23:30:14 UTC
README
本包为开发者提供网络工具。
注意:该包处于开发中,API可能会变更。
用法
Ping 请求
Ping 客户端为开发者提供一个统一的接口,用于通过 ping 命令行、PHP 套接字 API 或通用的 PHP fsocketopen 工具函数查询服务器是否存在。当使用操作系统 Ping 二进制文件执行查询时,您需要清理通过通信通道发送的数据,因为这些客户端通常不安全,不适合敏感数据。建议使用 Ping 客户端,因为它的速度通常比 PHP 实现更快。默认:二进制
// Import required classes & functions use Drewlabs\Net\Client; use Drewlabs\Net\Method; // Create a PING client $client = new Drewlabs\Net\Pring(<HOST>, [<PORT>, <TMIEOUT>]); // example $client = new Drewlabs\Net\Pring('https://liksoft.tg'); // Send request using default Channel $response = $client->request(); // Returns \Drewlabs\Net\PingResult class // Send a Ping request using PHP fsockopen util $response = $client->request(Method::FSOCKOPEN); // Get response details $response->latency(); // Returns the latency of the PING request $response->ip(); // Returns the IP address of the client