-
Notifications
You must be signed in to change notification settings - Fork 0
Recipes
Muhammet Şafak edited this page May 24, 2026
·
1 revision
Small, runnable end-to-end examples. Each links to a focused page with the full code and explanation.
| Recipe | Transport | What it shows |
|---|---|---|
| Recipe Echo Server | TCP, UDP | The simplest possible request / response server. |
| Recipe Chat Server | TCP |
register() for named clients, broadcast() for fan-out, quit command. |
| Recipe Broadcast | TCP & UDP | The three flavours of broadcast(): all, by-id, by-list. |
| Recipe Self Signed TLS | TLS | Generate a cert in pure PHP, bind a TLS server, connect with a TLS client. |
| Recipe SMTP Client | SSL | Raw EHLO exchange against Gmail's port 465. |
| Recipe Custom Channel | — | Implement your own ChannelInterface (in-memory, in-process pipe, …). |
- Every recipe assumes
composer require initphp/sockethas run and thevendor/autoload.phpis loaded. - Loopback (
127.0.0.1) is used for everything that needs a host so the snippets run unmodified. - TLS recipes generate self-signed material to keep the snippets self-contained. Do not ship that — see SSL Context Options for production-grade configuration.
- The recipes prefer
live()for the canonical pattern. To embed them in your own event loop, swaplive()for awhile (… $server->tick(…)) { … }shape — see Event Loop Integration.
initphp/socket · MIT · PHP 8.1+ · part of the InitPHP family · file issues at InitPHP/Socket/issues
Getting started
Transports
Concepts
Reference
Recipes
Operational