{"id":44939695,"url":"https://github.com/thenlabs/websocket-server","last_synced_at":"2026-02-18T08:06:33.623Z","repository":{"id":57068317,"uuid":"418676983","full_name":"thenlabs/websocket-server","owner":"thenlabs","description":"An asynchronous WebSocket server written in PHP.","archived":false,"fork":false,"pushed_at":"2022-03-26T11:43:01.000Z","size":351,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"1.0","last_synced_at":"2025-07-30T21:41:30.805Z","etag":null,"topics":["php","php-library","websocket","websocket-server","websocket-servers","websockets"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thenlabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-18T21:40:32.000Z","updated_at":"2023-07-27T20:34:18.000Z","dependencies_parsed_at":"2022-08-24T14:54:11.011Z","dependency_job_id":null,"html_url":"https://github.com/thenlabs/websocket-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thenlabs/websocket-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fwebsocket-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fwebsocket-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fwebsocket-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fwebsocket-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thenlabs","download_url":"https://codeload.github.com/thenlabs/websocket-server/tar.gz/refs/heads/1.0","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenlabs%2Fwebsocket-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29573463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T07:57:19.261Z","status":"ssl_error","status_checked_at":"2026-02-18T07:57:18.820Z","response_time":162,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","php-library","websocket","websocket-server","websocket-servers","websockets"],"created_at":"2026-02-18T08:06:33.016Z","updated_at":"2026-02-18T08:06:33.618Z","avatar_url":"https://github.com/thenlabs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# WebSocketServer\n\nAn asynchronous WebSocket server written in PHP.\n\n\u003eIf you like this project gift us a ⭐.\n\n## Installation.\n\n    $ composer require thenlabs/websocket-server 1.0.x-dev\n\n\u003eThis project has not a stable version yet.\n\n## Usage.\n\nIn the `example` directory exists a demo project which implements a bare chat server.\n\nThe `example/MyChatServer.php` file contain the class which, like you can see, implements the logic of the server through an event system.\n\n```php\n\u003c?php\n// example/MyChatServer.php\n\nuse ThenLabs\\WebSocketServer\\Event\\CloseEvent;\nuse ThenLabs\\WebSocketServer\\Event\\MessageEvent;\nuse ThenLabs\\WebSocketServer\\Event\\OpenEvent;\nuse ThenLabs\\WebSocketServer\\WebSocketServer;\n\nclass MyChatServer extends WebSocketServer\n{\n    protected $users = [];\n\n    public function onOpen(OpenEvent $event): void\n    {\n        $request = $event-\u003egetRequest();\n        $nickname = explode('/', $request-\u003egetRequestUri())[1];\n\n        // notify to the connected users previously.\n        foreach ($this-\u003eusers as $user) {\n            $user-\u003esend(\"User '{$nickname}' has connected.\");\n        }\n\n        // add the new user to the list.\n        $this-\u003eusers[$nickname] = $event-\u003egetConnection();\n    }\n\n    public function onMessage(MessageEvent $event): void\n    {\n        $senderUser = $event-\u003egetConnection();\n        $senderNick = array_search($senderUser, $this-\u003eusers);\n\n        $message = $event-\u003egetMessage();\n\n        // send the message to the other users.\n        foreach ($this-\u003eusers as $user) {\n            if ($user !== $senderUser) {\n                $user-\u003esend(\"{$senderNick}: {$message}\");\n            }\n        }\n    }\n\n    public function onClose(CloseEvent $event): void\n    {\n        $user = $event-\u003egetConnection();\n        $nickname = array_search($user, $this-\u003eusers);\n\n        // notify to the other users.\n        foreach ($this-\u003eusers as $otherUser) {\n            if ($otherUser !== $user) {\n                $otherUser-\u003esend(\"The user {$nickname} has disconnected.\");\n            }\n        }\n\n        unset($this-\u003eusers[$nickname]);\n    }\n}\n```\n\nThe `example/start-server.php` file contains the script which starts the server.\n\n```php\n\u003c?php\n// example/start-server.php\n\nrequire_once __DIR__.'/../vendor/autoload.php';\nrequire_once __DIR__.'/MyChatServer.php';\n\n$config = [\n    'host' =\u003e $argv[1] ?? '127.0.0.1',\n    'port' =\u003e $argv[2] ?? 9090,\n];\n\n$server = new MyChatServer($config);\n$server-\u003estart();\n```\n\nThis file should be executed as next:\n\n    $ php example/start-server.php\n\nIn order to test the example, we can use the `example/index.html` file which contains three clients which can be used like it's shown next:\n\n![](demo.gif)\n\n## Development.\n\n### Running the tests.\n\nStart the selenium server.\n\n    $ java -jar path/to/selenium-server-standalone-x.y.z.jar\n\nRun [PyramidalTests](https://github.com/thenlabs/pyramidal-tests).\n\n    $ ./vendor/bin/pyramidal\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenlabs%2Fwebsocket-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenlabs%2Fwebsocket-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenlabs%2Fwebsocket-server/lists"}