Skip to content

Instantly share code, notes, and snippets.

@payden
Last active December 29, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save payden/7741837 to your computer and use it in GitHub Desktop.
Save payden/7741837 to your computer and use it in GitHub Desktop.
php-ws example
<?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: '" . $msg->payload . "'\n";
echo "Echoing it back...\n";
$client->sendText($msg->payload);
};
$ws->run();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment