{"id":22425354,"url":"https://github.com/phppkg/websocket-server","last_synced_at":"2025-08-01T08:33:02.950Z","repository":{"id":56991582,"uuid":"86578997","full_name":"phppkg/websocket-server","owner":"phppkg","description":"a lighting webSocket application[NOTICE: It is a learning reference project]","archived":false,"fork":false,"pushed_at":"2018-03-27T14:17:54.000Z","size":581,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-16T04:11:44.493Z","etag":null,"topics":["php-library","php-socket","php-stream","swoole","websocket-application","websocket-client","websocket-server"],"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/phppkg.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}},"created_at":"2017-03-29T12:23:54.000Z","updated_at":"2023-01-31T22:32:26.000Z","dependencies_parsed_at":"2022-08-21T12:20:40.444Z","dependency_job_id":null,"html_url":"https://github.com/phppkg/websocket-server","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fwebsocket-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fwebsocket-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fwebsocket-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phppkg%2Fwebsocket-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phppkg","download_url":"https://codeload.github.com/phppkg/websocket-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228356390,"owners_count":17907191,"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":["php-library","php-socket","php-stream","swoole","websocket-application","websocket-client","websocket-server"],"created_at":"2024-12-05T19:13:53.313Z","updated_at":"2024-12-05T19:13:54.155Z","avatar_url":"https://github.com/phppkg.png","language":"PHP","readme":"# webSocket application\n\na lightweight webSocket application library\n\n## install\n\nin `composer.json` add:\n\n```\n\"inhere/websocket\": \"dev-master\",\n```\n\nrun: `composer up`\n\n## usage\n\n### only use webSocket server\n\n```php\nuse Inhere\\WebSocket\\WebSocketServer;\n\n$ws = new WebSocketServer();\n\n$ws-\u003eon('open', function (WebSocketServer $ws, $data) {\n    $ws-\u003esend('welcome!');\n});\n\n$ws-\u003eon(WebSocketServer::ON_MESSAGE, function (WebSocketServer $ws, $data) {\n    $ws-\u003esend(\"you input: $data\");\n});\n\n$ws-\u003estart();\n```\n### use the webSocket application\n\n```php\nuse Inhere\\WebSocket\\Application;\nuse Inhere\\WebSocket\\WebSocketServer;\n\n$app = new Application('', 9501);\n\n$app-\u003eonOpen(function (WebSocketServer $ws, Application $app, $id) {\n    $app-\u003erespond([\n        'total' =\u003e $ws-\u003ecount()\n    ], 'welcome!');\n});\n\n$app-\u003eonClose(function (WebSocketServer $ws, Application $app) {\n    $app-\u003erespond([\n        'total' =\u003e $ws-\u003ecount()\n    ]);\n});\n\n$rootHandler = $app-\u003eroute('/', new \\Inhere\\WebSocket\\handlers\\RootHandler());\n\n// commands\n$rootHandler-\u003eadd('test', function ($data, $index, Application $app) {\n\n    return 'hello';\n});\n```\n\n## webSocket header example\n\n### webSocket request header \n\n```\n// parsed code\nGET / HTTP/1.1\nHost: 127.0.0.1:9501\nConnection: Upgrade\nPragma: no-cache\nCache-Control: no-cache\nUpgrade: websocket\nOrigin: http://localhost:63342\nSec-WebSocket-Version: 13\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3018.3 Safari/537.36\nAccept-Encoding: gzip, deflate, sdch, br\nAccept-Language: zh-CN,zh;q=0.8\nCookie: _ga=GA1.1.1542925283.1469426767\nSec-WebSocket-Key: Tak3+4p37S5EAltSHDxpTw==\nSec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\n\n\n// source code\nGET ws://127.0.0.1:9501/ HTTP/1.1\nHost: 127.0.0.1:9501\nConnection: Upgrade\nPragma: no-cache\nCache-Control: no-cache\nUpgrade: websocket\nOrigin: http://localhost:63342\nSec-WebSocket-Version: 13\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3018.3 Safari/537.36\nAccept-Encoding: gzip, deflate, sdch, br\nAccept-Language: zh-CN,zh;q=0.8\nCookie: _ga=GA1.1.1542925283.1469426767\nSec-WebSocket-Key: BmMdv63hr1D/eS7eTD59Vw==\nSec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\n```\n\n### webSocket response header(handshake success)\n\n```\n// parsed code\nConnection:Upgrade\nSec-WebSocket-Accept:BOVf/XCi92SSib4Ga+ltTsmHiWQ=\nUpgrade:websocket\n\n// source code\nHTTP/1.1 101 Switching Protocol\nUpgrade: websocket\nConnection: Upgrade\nSec-WebSocket-Accept: BOVf/XCi92SSib4Ga+ltTsmHiWQ=\n```\n\n## license\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphppkg%2Fwebsocket-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphppkg%2Fwebsocket-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphppkg%2Fwebsocket-server/lists"}