sockets / php-stream-socket-server
Provides an async bootstrapable server for WebSockets
1.4.1
2016-10-24 00:51 UTC
Requires
- php: ^7.0
- ext-pcntl: *
Requires (Dev)
- codacy/coverage: ^1.0
- phpunit/phpunit: ^5.5
README
Packagist: https://packagist.org/packages/sockets/php-stream-socket-server
php-stream-socket-server
Provides a bootstrapable server for WebSockets
Requirements
- php 7.0.x
Features
- Support for WebSocket clients via HTTP/1.1 UPGRADE
- Accepts a standard TCP socket client connection
- Capable of broadcasting to all client WebSockets from a cli input
- Your PHP application can intercept all client messages and respond
- Capable of server push, on-demand to any connected client
- Exposes all server and client functionality to the PHP application
Installation
This project will strictly follow semantic versions.
Simply add to your composer.json
{
"require": {
"php": "^7.0",
"sockets/php-stream-socket-server": "^1.4"
}
}
and run composer install
Configuration
All configuration arguments can be set using environment variables
The StreamSocketDaemon
constructor takes an array of arguments that will configure the following;
- DEBUG: output will be displayed to help with debugging
- defaults:
false
- defaults:
- IP: defines the current machines public IP that a client will try to establish a socket connection to the server
- default:
127.0.0.1
- default:
- PORT: defines a port to bind to, to receive client socket requests
- default:
8082
- default:
- HOSTNAME: define a fully qualified domain name for this machine that a client will try to establish a socket connection to the server
- default:
localhost
- default:
Usage
To use, create a bootstrap like the one provided in the examples
directory.
Note: The callback will run for every client message the socket receives, it is within this Closure you would initialise your app and based on the contents of the message payload send response/s.
Road map
- Add capability to establish a UDP socket
- Add an example of a standard JavaScript
WebSocket
client