/php-ws

PHP extension for writing WebSocket servers in PHP.

Primary LanguageCOtherNOASSERTION

php-ws

PHP extension for writing WebSocket servers in PHP.

Autobahn WebSocket Test Suite Report

Build Status

Feel like writing your WebSocket servers in PHP? Why not.

<?php
$ws = new WebSocketServer();
$ws->bind("0.0.0.0", "8080");
$ws->onopen = function($client) {
  echo "New connection: " . $client->sockfd . "\n";
};
$ws->onclose = function($client) {
  echo "Closing connection: " . $client->sockfd . "\n";
};
$ws->onmessage = function($client, $msg) {
  echo "Received message from client (" . $client->sockfd . "): " . $msg->payload . "\n";
  echo "Sending it back...\n";
  $client->sendText($msg->payload);
};
$ws->run();
?>