{"id":22344222,"url":"https://github.com/hi-folks/lara-sock","last_synced_at":"2025-07-09T23:32:28.936Z","repository":{"id":113435515,"uuid":"600568154","full_name":"Hi-Folks/lara-sock","owner":"Hi-Folks","description":"[building in public] WebSocket Laravel package powered by Open Swoole","archived":false,"fork":false,"pushed_at":"2024-06-04T21:23:33.000Z","size":751,"stargazers_count":25,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T22:16:22.180Z","etag":null,"topics":["buildinpublic","laravel","openswoole","swoole","websocket","websocket-server"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/hi-folks/lara-sock","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/Hi-Folks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2023-02-11T22:14:46.000Z","updated_at":"2024-06-04T21:23:36.000Z","dependencies_parsed_at":"2023-05-29T01:45:15.404Z","dependency_job_id":null,"html_url":"https://github.com/Hi-Folks/lara-sock","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Hi-Folks/lara-sock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Flara-sock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Flara-sock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Flara-sock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Flara-sock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hi-Folks","download_url":"https://codeload.github.com/Hi-Folks/lara-sock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Flara-sock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264505250,"owners_count":23618909,"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":["buildinpublic","laravel","openswoole","swoole","websocket","websocket-server"],"created_at":"2024-12-04T09:09:05.983Z","updated_at":"2025-07-09T23:32:28.911Z","avatar_url":"https://github.com/Hi-Folks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LaraSock\n\n\n[![CI/CD Github Actions](https://img.shields.io/github/actions/workflow/status/hi-folks/lara-sock/php-code-quality.yml?style=for-the-badge)](https://github.com/Hi-Folks/lara-sock/actions)\n[![GitHub last commit](https://img.shields.io/github/last-commit/hi-folks/lara-sock?style=for-the-badge)](https://github.com/Hi-Folks/lara-sock/commits/main)\n[![GitHub Release Date](https://img.shields.io/github/release-date/hi-folks/lara-sock?style=for-the-badge)](https://github.com/Hi-Folks/lara-sock/releases)\n[![Packagist PHP Version](https://img.shields.io/packagist/v/hi-folks/lara-sock?style=for-the-badge)](https://packagist.org/packages/hi-folks/lara-sock)\n\n[![LaraSock](lara-sock.png)](https://github.com/Hi-Folks/lara-sock)\n\n\n\u003e This is an early stage (under construction/exploration) work in progress, so currently, the project only implements some of the functionalities you expect. Feel free to share if you [want to contribute](CONTRIBUTING.md), providing Pull Request or\n\u003e suggestions. We believe in positive vibes.\n\n\n## Why LaraSock?\n\nLarasock implements a WebSocket Server based on Open Swoole.\nThe final goal is to support the same Application Providers supported by Laravel Octane (Swoole and Roadrunner).\nThis package lets you easily add real-time functionalities via WebSocket to your Laravel/Octane application.\n\nSo, if you are already using Open Swoole with your Laravel Octane,\nyou don't need additional services or external tools to enable the Web Socket functionalities.\n\n\n## Installing LaraSock\n\nThe LaraSock `hi-folks/lara-sock` is provided as a PHP package that you can install in your Laravel project.\nTo install the package, you can use `composer require` command:\n\n```bash\ncomposer require hi-folks/lara-sock\n```\n\n\n## Starting the server\n\nInstalling the package in your Laravel project adds a new command with `php artisan`.\nThe new `larasock:start` artisan command starts a long live running process that starts a Web Socket server, ready to listen and accept your Web Socket connection from clients.\n\n```bash\nphp artisan larasock:start\n```\n\n### Options\n\nWith the command, you can use some options:\n\n```\n--host[=HOST]     The IP address the server should bind to [default: \"127.0.0.1\"]\n--port[=PORT]     The port the server should be available on [default: \"9501\"]\n```\nThe default host is `127.0.0.1`, which means that\nit can receive connections from localhost clients.\nThe default port is `9501`.\n\nIf you want to accept connections from all the clients on the network,\nyou have to \"bind\" to `0.0.0.0` IP address:\n\n```shell\nphp artisan larasock:start --host=0.0.0.0\n```\n\nIf you have Tmux installed, you can use it to start the Octane Web server and the WebSocket server on the same screen.\n```shell\ntmux \\\n    new-session  'php artisan octane:start' \\; \\\n    split-window 'php artisan larasock:start --logchannel=stderr' \\; \\\n    detach-client\ntmux a\n```\n### The client\nOnce you start the Web Socket Server, you can create your Web client to send and receive messages.\nYou can implement your HTML page using the WebSocket Javascript class.\n\n```html\n\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\n\u003chead\u003e\n    \u003ctitle\u003e WebSocket with PHP and Open Swoole \u003c/title\u003e\n    \u003clink href=\"https://cdn.jsdelivr.net/npm/daisyui@2.50.0/dist/full.css\" rel=\"stylesheet\" type=\"text/css\" /\u003e\n    \u003cscript src=\"https://cdn.tailwindcss.com\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n        let echo_service;\n        append = function(text) {\n            document.getElementById(\"websocket_events\").insertAdjacentHTML('afterbegin',\n                \"\u003cli class='border-solid border-y-2 border-indigo-400'\u003e\" + text + \";\u003c/li\u003e\"\n            );\n        }\n        window.onload = function() {\n            echo_service = new WebSocket('ws://127.0.0.1:9501');\n            echo_service.onmessage = function(event) {\n                console.log(event.data)\n                append(event.data)\n            }\n            echo_service.onopen = function() {\n                append(\"Connected to WebSocket!\");\n            }\n            echo_service.onclose = function() {\n                append(\"Connection closed\");\n            }\n            echo_service.onerror = function() {\n                append(\"Error happens\");\n            }\n        }\n\n        function sendMessage(event) {\n            console.log(event)\n            let message = document.getElementById(\"message\").value;\n            echo_service.send(message);\n        }\n    \u003c/script\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n    \u003cdiv class=\" px-20 py-20\" data-theme=\"acid\"\u003e\n        Message:\n        \u003cdiv class=\"form-control\"\u003e\n            \u003cdiv class=\"input-group\"\u003e\n                \u003cinput id=\"message\" value=\"Hello!\" type=\"text\" placeholder=\"Search…\" class=\"input input-bordered\" /\u003e\n                \u003cbutton class=\"btn btn-square\" onclick=\"sendMessage(event)\"\u003e\n                    \u003csvg xmlns=\"http://www.w3.org/2000/svg\" class=\"h-6 w-6\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\"\u003e\n                        \u003cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z\" /\u003e\n                    \u003c/svg\u003e\n                \u003c/button\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n        \u003cul class=\"p-4\" id=\"websocket_events\"\u003e\n        \u003c/ul\u003e\n    \u003c/div\u003e\n\u003c/body\u003e\n\n\u003c/html\u003e\n```\n## A note about the Subprotocol\n\nWebSocket defines a protocol that allows clients and servers to exchange data (messages).\nA **Sub**-protocol defines the exchange message's structure and the meanings of each field. For example, you want to exchange a pure string with a text message without additional information. Or you want to exchange data with a more complex structure.\n\nThe current implementation of this Proof of Concept exchanges messages in string format.\n\n\n## Next Step, the evolution of the Proof of Concept\n\nThis is just a Proof of Concept, the thing that I would like to focus on (and feel free to share any suggestion/feedback/pull request):\n\n- Define the structure of the message\n- Allow customising the broadcast method\n- Rest API for showing statistics\n\nThe package is under construction, so if you have some suggestions, you can:\n- [Write a Feature request](https://github.com/Hi-Folks/lara-sock/issues/new?labels=feature-request\u0026title=%5BFeature+Request%5D%3A++)\n- [Submit a Pull Request](https://github.com/Hi-Folks/lara-sock/pulls)\n- [Write me on Twitter](https://twitter.com/RmeetsH)\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Submit ideas or feature requests, or issues\n\nThe package is under construction, so if you have some suggestions, you can:\n\n* Take a look if your request is already there [https://github.com/Hi-Folks/lara-sock/issues](https://github.com/Hi-Folks/lara-sock/issues)\n* If it is not present, you can create a new [feature request](https://github.com/Hi-Folks/lara-sock/issues/new?labels=feature-request\u0026title=%5BFeature+Request%5D%3A++)\n* [Submit a Pull Request](https://github.com/Hi-Folks/lara-sock/pulls)\n* [Write me a message via Twitter](https://twitter.com/RmeetsH)\n\n## Credits\n\n- [Roberto Butti](https://github.com/roberto-butti)\n- [All Contributors](https://github.com/Hi-Folks/lara-sock/graphs/contributors)\n\n## Who talks about LaraSock\n- [Teasing Tweet](https://twitter.com/RmeetsH/status/1625631431664836608)\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi-folks%2Flara-sock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhi-folks%2Flara-sock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi-folks%2Flara-sock/lists"}