diff --git a/composer.json b/composer.json index 9d76a31..d92cd4b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "bloatless/php-websocket", + "name": "r-martins/php-websocket", "description": "A simple WebSocket Server and Client implementation in PHP.", "keywords": [ "php", diff --git a/src/Application/Application.php b/src/Application/Application.php index d2c090a..4d1a8e2 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -16,7 +16,7 @@ protected function __construct() // singleton construct required this method to be protected/private } - final protected function __clone() + private function __clone() { // singleton construct required this method to be protected/private } diff --git a/src/Connection.php b/src/Connection.php index 38b091b..9659c28 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -50,6 +50,11 @@ class Connection */ private string $dataBuffer = ''; + /** + * @var array $queryParams + */ + private array $queryParams = []; + /** * @param Server $server * @param resource $socket @@ -93,6 +98,13 @@ private function handshake(string $data): bool $path = $matches[1]; $applicationKey = substr($path, 1); + // check for GET parameters (?a=123&b=456) + if ($pos = strpos($applicationKey, '?')) { + parse_str(substr($applicationKey, $pos + 1), $queryParams); + $this->queryParams = $queryParams; + $applicationKey = substr($applicationKey, 0, $pos -1); + } + if ($this->server->hasApplication($applicationKey) === false) { $this->log('Invalid application: ' . $path); $this->sendHttpResponse(404); @@ -598,4 +610,24 @@ public function getClientApplication(): ?ApplicationInterface { return $this->application; } + + /** + * Returns the querystrings parameters passed by the connecting client + * @return array + */ + public function getQueryParams() + { + return $this->queryParams; + } + + /** + * Return specific querystring parameter passed by the connecting client + * @param $param + * + * @return mixed|null + */ + public function getQueryParam($param) + { + return (isset($this->queryParams[$param])) ? $this->queryParams[$param] : null; + } } diff --git a/src/PushClient.php b/src/PushClient.php index f86c28b..ac6214c 100644 --- a/src/PushClient.php +++ b/src/PushClient.php @@ -73,7 +73,7 @@ private function sendPayloadToServer(IPCPayload $payload): bool } $bytesSend = socket_sendto($socket, $dataToSend, $dataLength, MSG_EOF, $this->ipcSocketPath, 0); if ($bytesSend <= 0) { - throw new \RuntimeException('Could not sent data to IPC socket.'); + throw new \RuntimeException('Could not sent data to IPC socket. ' . socket_strerror(socket_last_error()) . '.'); } socket_close($socket);