phpwebsocket

授权协议 GPLv3
开发语言 PHP
所属分类 Web应用开发、 WebSocket开发包
软件类型 开源软件
地区 不详
投 递 者 林修真
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

从名字上也可看出,这是一个 WebSocket 的 PHP 实现。

示例客户端代码:

var host = "ws://localhost:12345/websocket/server.php";
try{
  socket
= new WebSocket(host);
  log
('WebSocket - status '+socket.readyState);
  socket
.onopen    = function(msg){ log("Welcome - status "+this.readyState); };
  socket
.onmessage = function(msg){ log("Received: "+msg.data); };
  socket
.onclose   = function(msg){ log("Disconnected - status "+this.readyState); };
}
catch(ex){ log(ex); }

 

示例服务器端代码:

log("Handshaking...");
list
($resource,$host,$origin) = getheaders($buffer);
$upgrade
= "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
           
"Upgrade: WebSocket\r\n" .
           
"Connection: Upgrade\r\n" .
           
"WebSocket-Origin: " . $origin . "\r\n" .
           
"WebSocket-Location: ws://" . $host . $resource . "\r\n" .
           
"\r\n";
$handshake
= true;
socket_write
($socket,$upgrade.chr( ),strlen($upgrade.chr( )));