{"id":15026389,"url":"https://github.com/warriorxk/phpwebsockets","last_synced_at":"2025-04-09T20:21:14.061Z","repository":{"id":48873781,"uuid":"62372735","full_name":"WarriorXK/PHPWebSockets","owner":"WarriorXK","description":"A PHP 7.3+ library to accept and create websocket connections","archived":false,"fork":false,"pushed_at":"2024-12-06T15:21:32.000Z","size":629,"stargazers_count":12,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T20:47:16.489Z","etag":null,"topics":["daemon","php","php-daemon","php73","php74","websocket","websocket-client","websocket-connection","websocket-connections","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/WarriorXK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-01T07:14:20.000Z","updated_at":"2024-10-19T10:14:03.000Z","dependencies_parsed_at":"2025-02-15T20:32:51.299Z","dependency_job_id":"20c135ff-486b-4d11-8218-3ab2e07ff149","html_url":"https://github.com/WarriorXK/PHPWebSockets","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarriorXK%2FPHPWebSockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarriorXK%2FPHPWebSockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarriorXK%2FPHPWebSockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WarriorXK%2FPHPWebSockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WarriorXK","download_url":"https://codeload.github.com/WarriorXK/PHPWebSockets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248104232,"owners_count":21048304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["daemon","php","php-daemon","php73","php74","websocket","websocket-client","websocket-connection","websocket-connections","websocket-server","websocket-servers","websockets"],"created_at":"2024-09-24T20:04:23.831Z","updated_at":"2025-04-09T20:21:13.984Z","avatar_url":"https://github.com/WarriorXK.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPWebSockets\n[![Code documented](https://codedocs.xyz/WarriorXK/PHPWebSockets.svg)](https://codedocs.xyz/WarriorXK/PHPWebSockets/) Master: [![Build Status](https://travis-ci.com/WarriorXK/PHPWebSockets.svg?branch=master)](https://travis-ci.com/WarriorXK/PHPWebSockets) Develop: [![Build Status](https://travis-ci.com/WarriorXK/PHPWebSockets.svg?branch=develop)](https://travis-ci.com/WarriorXK/PHPWebSockets)\n\nA PHP library to accept and create websocket connections, we aim to be 100% compliant with the websocket RFC and use the [Autobahn test suite](http://autobahn.ws/testsuite/) to ensure so.\nCurrently the server and the client are 100% compliant with the autobahn testsuite minus a few non-strict notices, the [compression extension](https://tools.ietf.org/html/rfc7692) for websockets will be implemented later\n\n## Server\nFor websocket servers a new \\PHPWebSockets\\Server instance should be created with a bind address and a port to listen on.\nFor ease of use you can use the UpdatesWrapper class, this will trigger certain callables set on basic functions.\n\nA basic websocket echo server would be:\n\n```php\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n$wrapper = new \\PHPWebSockets\\UpdatesWrapper();\n$wrapper-\u003esetMessageHandler(function(\\PHPWebSockets\\AConnection $connection, string $message, int $opcode) {\n\n    echo 'Got message with length ' . strlen($message) . PHP_EOL;\n    $connection-\u003ewrite($message, $opcode);\n\n});\n\n\n$server = new \\PHPWebSockets\\Server('tcp://0.0.0.0:9001');\n\nwhile (TRUE) {\n    $wrapper-\u003eupdate(0.1, $server-\u003egetConnections(TRUE));\n}\n```\n\nIf more control is required you can manually call ```$server-\u003eupdate(0.1);``` instead of using the wrapper, this will yield update objects which can be responded to.\n\n## Client\nFor connecting to a server the \\PHPWebSockets\\Client class should be constructed and the method connect($address, $port, $path) should be used to connect.\nFor ease of use you can again use the UpdatesWrapper class or use ```$server-\u003eupdate(0.1);``` for better control.\n\nA basic websocket echo client would be:\n\n```php\nrequire_once __DIR__ . '/../vendor/autoload.php';\n\n$wrapper = new \\PHPWebSockets\\UpdatesWrapper();\n$wrapper-\u003esetMessageHandler(function(\\PHPWebSockets\\AConnection $connection, string $message, int $opcode) {\n\n    echo 'Got message with length ' . strlen($message) . PHP_EOL;\n    $connection-\u003ewrite($message, $opcode);\n\n});\n\n\n$client = new \\PHPWebSockets\\Client();\nif (!$client-\u003econnect('tcp://localhost:9001/webSocket')) {\n    die('Unable to connect to server: ' . $client-\u003egetLastError() . PHP_EOL);\n}\n\nwhile (TRUE) {\n    $wrapper-\u003eupdate(0.1, [$client]);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarriorxk%2Fphpwebsockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarriorxk%2Fphpwebsockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarriorxk%2Fphpwebsockets/lists"}