PHP code example of overtrue / websocket

1. Go to this page and download the library: Download overtrue/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/ */

    

overtrue / websocket example snippets


use Overtrue\WebSocket\Server;

$options = [
    // 'port' => 8000,
    // 'timeout' => 0,
    // ...
];
$server = new Server($options);

$server->accept();

// receive
$message = $server->reveive();

// send
$server->send('Hello overtrue.');

use Overtrue\WebSocket\Client;

$client = new Client('ws://127.0.0.1:8000');

// send
$client->send('Hello overtrue.');

// receive
$message = $client->reveive();