for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Fructify\Reload\Protocol\WebSocket;
use Fructify\Reload\Response\ResponseWebSocket;
/**
* Description of WebSocket
*
* @author ricky
*/
class WebSocket
{
const MIN_WS_VERSION = 13;
const MAGIC_GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
protected $messageQueue;
public function __construct()
$this->messageQueue = new MessageQueue();
}
* @return Frame
public function onMessage($data)
$this->messageQueue->add($data);
return Frame::parse($this->messageQueue);
public function handshake($request)
$key = $request->headers->get('Sec-WebSocket-Key');
if(
strtolower($request->headers->get('Upgrade')) != 'websocket' ||
!$this->checkProtocolVrsion($request) ||
!$this->checkSecKey($key)
){
return false;
$acceptKey = $this->generateAcceptKey($key);
$response = new ResponseWebSocket();
$response->headers->set('Sec-WebSocket-Accept', $acceptKey);
return $response;
protected function generateAcceptKey($key)
return base64_encode(sha1($key.static::MAGIC_GUID, true));
protected function checkSecKey($key)
return strlen(base64_decode($key)) == 16;
protected function checkProtocolVrsion($request)
return $request->headers->get('Sec-WebSocket-Version', 0) >= static::MIN_WS_VERSION;
//put your code here