{"id":19218698,"url":"https://github.com/fadilxcoder/websocket-php-html","last_synced_at":"2025-02-23T09:14:46.246Z","repository":{"id":86245805,"uuid":"530800014","full_name":"fadilxcoder/websocket-php-html","owner":"fadilxcoder","description":"PHP websocket - Client / Server","archived":false,"fork":false,"pushed_at":"2022-09-08T18:21:09.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-04T19:23:26.618Z","etag":null,"topics":["cli","client-server","html","notes","php","poc","websocket"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fadilxcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-08-30T19:25:29.000Z","updated_at":"2022-08-30T19:29:56.000Z","dependencies_parsed_at":"2023-03-08T10:00:35.805Z","dependency_job_id":null,"html_url":"https://github.com/fadilxcoder/websocket-php-html","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadilxcoder%2Fwebsocket-php-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadilxcoder%2Fwebsocket-php-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadilxcoder%2Fwebsocket-php-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadilxcoder%2Fwebsocket-php-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fadilxcoder","download_url":"https://codeload.github.com/fadilxcoder/websocket-php-html/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240292395,"owners_count":19778311,"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":["cli","client-server","html","notes","php","poc","websocket"],"created_at":"2024-11-09T14:27:47.430Z","updated_at":"2025-02-23T09:14:46.104Z","avatar_url":"https://github.com/fadilxcoder.png","language":"PHP","readme":"# Notes (SERVER)\n\n- Install dependencies - `composer install`\n- Create `src/socket.php`\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Ratchet\\MessageComponentInterface;\nuse Ratchet\\ConnectionInterface;\n\nclass Socket implements MessageComponentInterface {\n\n    public function __construct()\n    {\n        $this-\u003eclients = new \\SplObjectStorage;\n    }\n\n    public function onOpen(ConnectionInterface $conn) \n    {\n        ....\n    }\n\n    public function onMessage(ConnectionInterface $from, $msg) \n    {\n        ....\n    }\n\n    public function onClose(ConnectionInterface $conn) \n    {\n        ....\n    }\n\n    public function onError(ConnectionInterface $conn, \\Exception $e) \n    {\n        ....\n    }\n}\n```\n\n- Create `run` php bash script - Executable in CLI\n\n```php\n#!/usr/bin/env php\n\n\u003c?php\n\nuse Ratchet\\Server\\IoServer;\nuse Ratchet\\Http\\HttpServer;\nuse Ratchet\\WebSocket\\WsServer;\nuse App\\Socket;\n\nrequire dirname( __FILE__ ) . '/vendor/autoload.php';\n\n$server = IoServer::factory(\n    new HttpServer(\n        new WsServer(\n            new Socket()\n        )\n    ),\n    8088 // \u003c--------------------------\n);\n\n$server-\u003erun();\n```\n\n- **NB** Run script using **CLI - Command Prompt** (Security measures)\n- RUN `php run` to launch local web socket server\n---\n\n\n# Notes (CLIENT)\n\n```js\n\n// Create a new WebSocket.\n\n//var socket  = new WebSocket('ws://127.0.0.1:8088');\nvar socket  = new WebSocket(\"ws://192.168.100.XX:8088\");\n\nvar message = document.getElementById('message');\n\nfunction transmitMessage() {\n    socket.send( message.value );\n}\n\nsocket.onmessage = function(e) {\n    alert( e.data );\n}\n```\n\nURL : http://localhost/websocket/ - use local tunnel / ngrok (Will work on same network)\n\n\u003cimg src=\"app.PNG\"/\u003e","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffadilxcoder%2Fwebsocket-php-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffadilxcoder%2Fwebsocket-php-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffadilxcoder%2Fwebsocket-php-html/lists"}