Download the PHP package moebius/socket without Composer
On this page you can find all versions of the php package moebius/socket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moebius/socket
More information about moebius/socket
Files in moebius/socket
Package socket
Short Description A coroutine based socket client and server implementation.
License MIT
Informations about the package socket
moebius/socket
An easy to use interface for working with many simultaneous and non-blocking network connections.
Note! A default build of PHP limit the number of concurrent "polling" connections to 1024. This limitation can be overcome by running multiple server processes, or by recompiling PHP.
Architecture
This library provides three core classes which you can use to create network clients or server implementations.
-
Moebius\Socket\Client
provides an API to thestream_socket_client()
function in PHP, and can be used to create concurrent HTTP clients. -
Moebius\Socket\Server
provides an API to thestream_socket_server()
function, and lets you create servers that accepts connections and gives you connection instances for every new client that connects. Moebius\Socket\Connection
is similar to the Client class, but connections are initiated externally and returned by the Server class.
Example client
Example server
Complete working example
To issue multiple concurrent requests, you simply wrap run your code via the
M\go(callable $callbacl)
function. This way you can perform a lot of requests
at the same time.
API
-
Client::__construct(string $address, ClientOptions|array $options=[])
. Creates an instance of the socket client, but does not perform any network operations. -
Client::connect()
. Non-blocking connect to server. (The DNS lookup operation may block at the moment) -
Client::disconnect()
. Close the connection. Client::read(int $length): string
. Read$length
bytes from the server. You may want to perform this via theM\go(callable $coroutine)
function if you want to issue multiple requests