grok-s / socket
Full-featured, open-source WebSocket library for PHP (Socket.IO-like: events, rooms, ACKs, auth, encryption, DB integration)
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/grok-s/socket
Requires
- php: >=8.0
- ext-openssl: *
- ext-sockets: *
Suggests
- firebase/php-jwt: For JWT authentication in middleware
README
Pure PHP, Socket.IO-like WebSocket server with:
- Events, rooms, namespaces
- One-to-one & group chat
- Broadcasting
- JWT Auth middleware
- AES-256 encryption
- Database integration
- Auto-reconnect client
- Full PHPDoc (VS Code hover)
- Laravel ready
Install
composer require grok-s/socket
Why GrokSocket?
- Easy to Use: API like Socket.IO for quick setup.
- Full Features: Events, rooms (for chats), broadcasting, ACKs, middleware (auth), encryption (AES-256), DB examples.
- Integrations: Plain PHP, Laravel (service provider), others.
- Secure: WSS, message encryption.
- Open-Source: MIT – contribute on GitHub!
Example code and image
here is example code running from php ws/server.php start you can copy these code and try to connect with same ip address or localhost with port
<?php require 'vendor/autoload.php'; use Grok\Socket\Server; $server = new Server('127.0.0.1', 8282); // $server->setEncryptionKey('your-secret-key-here'); // Optional: AES-256 // Basic event handling $server->on('connection', function($socket) { echo "Client connected: " . $socket->getId() . "\n"; $socket->emit('welcome', 'Hello from GrokSocket!'); }); $server->on('chat', function($client, $data) use ($server) { echo "Message from " . $client->getId() . ": " . (is_string($data) ? $data : json_encode($data)) . "\n"; }); $server->on('disconnect', function($client) { echo "Client disconnected: " . $client->getId() . "\n"; }); $server->run(); // Starts the server
to learn more explore docs and example folder, you can use it with any production application.