1. Go to this page and download the library: Download chrome-php/wrench 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/ */
chrome-php / wrench example snippets
// An example application, that just echoes the received
// data back to the connection that sent it
$app = new class implements \Wrench\Application\DataHandlerInterface
{
public function onData(string $data, \Wrench\Connection $connection): void
{
$connection->send($data);
}
};
// A websocket server, listening on port 8000
$server = new \Wrench\BasicServer('ws://localhost:8000', [
'allowed_origins' => [
'mysite.com',
'mysite.dev.localdomain'
],
]);
$server->registerApplication('echo', $app);
$server->registerApplication('chat', new \My\ChatApplication());
$server->setLogger($monolog); // PSR3
$server->run();
// A client side example, that sends a string and will receive
// the data back to the connection that sent it
$client = new Client('ws://localhost:8000', 'http://localhost:8000');
$client->connect();
$client->sendData('hello');
$response = $client->receive()[0]->getPayload();
$client->disconnect();
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.