Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 32 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class Connection
*/
private string $dataBuffer = '';

/**
* @var array $queryParams
*/
private array $queryParams = [];

/**
* @param Server $server
* @param resource $socket
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/PushClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down