john-jun / socket-client
A simple socket client library
1.0.0
2020-06-05 08:20 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2025-04-05 18:39:46 UTC
README
A simple socket client library
Install
To install with composer
composer require john-jun/socket-client
Test
composer test
Usage
use Air\SocketClient\NetAddress\TcpNetAddress; use Air\SocketClient\Socket; $socketClient = new Socket(new TcpNetAddress('domain or ipv4', 443, true)); //connect & get connect use time $socketClient->connect(); $socketClient->getConnectUseTime(); //http $http = "GET /social/poster/share/xx HTTP/1.1\r\n"; $http .= "Host: dev-restful.moftech.net\r\n"; $http .= "Accept: */*\r\n"; $http .= "User-Agent: " . PHP_VERSION . "\r\n"; $http .= "Connection: keep-alive\r\n\r\n"; //send & recv $socketClient->send($http); $result = $socketClient->recv(); //the $result 'HTTP/1.1 200 OK Cache-Control: no-cache, private Content-Type: application/json Date: Mon, 25 May 2020 09:58:00 GMT Server: nginx X-Powered-By: PHP/7.3.15 Content-Length: 26 Connection: keep-alive {"code":"0","response":[]}';