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
composer require grok-s/socket- 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!
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 serverto learn more explore docs and example folder, you can use it with any production application.