Download the PHP package phasync/server without Composer
On this page you can find all versions of the php package phasync/server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phasync/server
More information about phasync/server
Files in phasync/server
Package server
Short Description A high performance async TCP and UDP socket server for PHP.
License MIT
Informations about the package server
phasync/server
Note: This package will be renamed to
phasync/netin a future release.
Efficient TCP and UDP networking for PHP using phasync coroutines.
All stream resources are wrapped with AsyncStream, providing transparent async I/O - no need to call phasync::readable() or phasync::writable() manually.
Installation
TcpServer
Accept TCP connections using a simple iterator pattern:
Multiple Listen Addresses
Listen on multiple ports or interfaces simultaneously:
Unix Domain Sockets
API
Dns
Async DNS resolution (used automatically by TcpClient):
Features:
- Non-blocking UDP queries to system nameserver
- IPv4 (A) and IPv6 (AAAA) support
- Random selection for load balancing when multiple records exist
resolveAll()to get all IPs- Reads
/etc/hostsfirst (both IPv4 and IPv6 entries) - Caches results using DNS TTL
- Falls back to 8.8.8.8 if no nameserver configured
API
TcpClient
Connect to TCP servers asynchronously (with async DNS):
Unix Domain Sockets
API
UdpServer
Receive UDP datagrams with correct reply routing:
Multiple Interfaces
When bound to multiple interfaces, the $socket returned ensures replies come from the correct source IP:
API
Performance
These implementations leverage phasync coroutines and non-blocking I/O for high performance:
- Zero-copy buffers: Read/write buffers are disabled for direct kernel access
- TCP_NODELAY: Disabled Nagle algorithm for low-latency responses
- SO_REUSEPORT: Enabled by default for graceful restarts and multi-process scaling
- Large chunk size: 64KB chunks for efficient data transfer
In synthetic benchmarks, this can handle 50% more requests per second than Node.js.
Design Guidelines
Read/Write Strategy
- Read big: Always read large chunks (65536 bytes) and buffer yourself if needed
- Write for your use case: Large chunks for bandwidth, small chunks for low latency
Socket Options
| Option | Default | Reason |
|---|---|---|
so_reuseport |
true |
Graceful restarts, multi-process scaling |
tcp_nodelay |
true |
Low-latency delivery of small messages |
backlog |
511 |
Handle connection bursts |
Override via the $context parameter:
Deprecated: Server Class
The original Server class is deprecated. Migrate to TcpServer or UdpServer: