{"id":26728333,"url":"https://github.com/valtzu/guzzle-websocket-middleware","last_synced_at":"2025-07-04T23:06:29.580Z","repository":{"id":239199932,"uuid":"798409691","full_name":"valtzu/guzzle-websocket-middleware","owner":"valtzu","description":"Connect to a WebSocket server using Guzzle HTTP client","archived":false,"fork":false,"pushed_at":"2025-03-27T16:04:32.000Z","size":23,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-17T21:46:50.292Z","etag":null,"topics":["guzzle","guzzle-middleware","php8","websocket","ws","wss"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/valtzu/guzzle-websocket-middleware","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/valtzu.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,"zenodo":null}},"created_at":"2024-05-09T18:06:23.000Z","updated_at":"2025-03-27T16:04:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"8617b342-138d-43d2-9fb1-d121c8bc04d4","html_url":"https://github.com/valtzu/guzzle-websocket-middleware","commit_stats":null,"previous_names":["valtzu/guzzle-websocket-middleware"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/valtzu/guzzle-websocket-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valtzu%2Fguzzle-websocket-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valtzu%2Fguzzle-websocket-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valtzu%2Fguzzle-websocket-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valtzu%2Fguzzle-websocket-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valtzu","download_url":"https://codeload.github.com/valtzu/guzzle-websocket-middleware/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valtzu%2Fguzzle-websocket-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260559007,"owners_count":23027730,"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":["guzzle","guzzle-middleware","php8","websocket","ws","wss"],"created_at":"2025-03-27T22:23:12.303Z","updated_at":"2025-07-04T23:06:29.560Z","avatar_url":"https://github.com/valtzu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Connect to WebSocket endpoints with Guzzle HTTP client\n\n**NOTE:** Only `StreamHandler` supported (so not `CurlHandler`!).\n\n### Installation\n\n```\ncomposer require valtzu/guzzle-websocket-middleware\n```\n\n### Usage\n\nGuzzle's `synchronous` option is used to configure the stream blocking option.\n\n#### Synchronous usage\n\n```php\n$handlerStack = new HandlerStack(new StreamHandler());\n$handlerStack-\u003eunshift(new WebSocketMiddleware());\n\n$guzzle = new Client(['handler' =\u003e $handlerStack]);\n\n$handshakeResponse = $guzzle-\u003erequest('GET', 'wss://ws.postman-echo.com/raw');\n$ws = $handshakeResponse-\u003egetBody();\n\n$ws-\u003ewrite(\"Hello world\");\n$helloWorld = $ws-\u003eread(); // This will block until the reply frame is received\n```\n\n#### Asynchronous usage\n\n```php\n$handlerStack = new HandlerStack(new StreamHandler());\n$handlerStack-\u003eunshift(new WebSocketMiddleware());\n\n$guzzle = new Client(['handler' =\u003e $handlerStack]);\n\n$handshakeResponse = $guzzle-\u003erequestAsync('GET', 'wss://ws.postman-echo.com/raw')-\u003ewait();\n$ws = $handshakeResponse-\u003egetBody();\n\n$ws-\u003ewrite(\"Hello world\");\n$helloWorld = $ws-\u003eread(); // Here you may get an empty string if data wasn't received yet\n```\n\n#### Connection upkeep / ping-pong\n\nWhenever you read from a websocket stream, instead of receiving a text/binary frame, you may receive \"ping\" instead.\nWhen this happens, we automatically respond with \"pong\". However, due to being PHP (usually) being single-threaded,\nthis means that you must make sure `read` (even with `0` length) is done frequently enough.\n\nIt's also possible to manually send a ping – however, it does not wait for the other party to reply.\n\n```php\n$ws-\u003eping();\n```\n\n### Contributing\n\n1. If you have an issue with package, or you have a feature request, please open an issue\n1. If you want to contribute code, you may submit a Pull Request. Just remember to add tests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaltzu%2Fguzzle-websocket-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaltzu%2Fguzzle-websocket-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaltzu%2Fguzzle-websocket-middleware/lists"}