PHP code example of zanderwar / php-websocket

1. Go to this page and download the library: Download zanderwar/php-websocket library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zanderwar / php-websocket example snippets


// Require neccessary files here...

$server = new \Bloatless\WebSocket\Server('127.0.0.1', 8000);

// Server settings:
$server->setMaxClients(100);
$server->setCheckOrigin(false);
$server->setAllowedOrigin('foo.lh');
$server->setMaxConnectionsPerIp(100);
$server->setMaxRequestsPerMinute(2000);

// Add your applications here:
$server->registerApplication('status', \Bloatless\WebSocket\Application\StatusApplication::getInstance());
$server->registerApplication('demo', \Bloatless\WebSocket\Application\DemoApplication::getInstance());

$server->run();


$client = new \Bloatless\WebSocket\Client;
$client->connect('127.0.0.1', 8000, '/demo', 'foo.lh');
$client->sendData([
    'action' => 'echo',
    'data' => 'Hello Wolrd!'
]);