-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
Muhammet Şafak edited this page May 24, 2026
·
1 revision
composer require initphp/socketThe package follows Semantic Versioning. The current major is 2.x.
{
"require": {
"initphp/socket": "^2.0"
}
}| Requirement | Version | Why |
|---|---|---|
| PHP | ^8.1 |
The package uses enums, readonly promoted properties, intersection types and other 8.1+ features. |
| ext-sockets | bundled in PHP | Backs the TCP and UDP transports (socket_create, socket_bind, …). |
| ext-openssl | bundled in PHP | Powers the tls:// and ssl:// stream wrappers. |
Heads-up:
ext-socketsships with PHP but is occasionally disabled in shared hosting builds. Runphp -m | grep socketsif you are not sure.
| Extension | Purpose |
|---|---|
| ext-pcntl | Required only to run the package's TLS integration test suite (the test forks a child process for the client side of the handshake). Production code never depends on it. |
| ext-pcov or ext-xdebug | Code coverage when running the test suite. CI uses pcov for speed. |
A one-liner that exercises both the factory and the runtime:
require __DIR__ . '/vendor/autoload.php';
use InitPHP\Socket\Socket;
use InitPHP\Socket\Enum\Transport;
$server = Socket::server(Transport::TCP, '127.0.0.1', 9000);
echo get_class($server), PHP_EOL;
// InitPHP\Socket\Server\TCPIf that prints the class name, your install is good. No socket was bound; the factory returns a configured-but-passive server.
- Run the Quick Start for an end-to-end echo example.
- Skim the Architecture page if you want to understand how the pieces fit together before reading the API.
initphp/socket · MIT · PHP 8.1+ · part of the InitPHP family · file issues at InitPHP/Socket/issues
Getting started
Transports
Concepts
Reference
Recipes
Operational