{"id":13405424,"url":"https://github.com/takielias/codeigniter-websocket","last_synced_at":"2025-08-20T08:33:32.896Z","repository":{"id":41344713,"uuid":"160912228","full_name":"takielias/codeigniter-websocket","owner":"takielias","description":"Codeigniter WebSocket Built for real-time application.","archived":false,"fork":false,"pushed_at":"2022-05-31T17:30:37.000Z","size":53,"stargazers_count":57,"open_issues_count":8,"forks_count":30,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-15T23:07:46.882Z","etag":null,"topics":["broadcast-messages","codeigniter-library","codeigniter-websocket","php-websocket","ratchet","realtime-messaging","websocket","websockets"],"latest_commit_sha":null,"homepage":"https://ebuz.xyz","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/takielias.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":null},"created_at":"2018-12-08T06:45:28.000Z","updated_at":"2024-12-14T18:44:15.000Z","dependencies_parsed_at":"2022-09-01T14:10:38.773Z","dependency_job_id":null,"html_url":"https://github.com/takielias/codeigniter-websocket","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takielias%2Fcodeigniter-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takielias%2Fcodeigniter-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takielias%2Fcodeigniter-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takielias%2Fcodeigniter-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takielias","download_url":"https://codeload.github.com/takielias/codeigniter-websocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229886592,"owners_count":18139504,"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":["broadcast-messages","codeigniter-library","codeigniter-websocket","php-websocket","ratchet","realtime-messaging","websocket","websockets"],"created_at":"2024-07-30T19:02:01.726Z","updated_at":"2024-12-19T09:08:06.616Z","avatar_url":"https://github.com/takielias.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/takielias"],"categories":["PHP"],"sub_categories":[],"readme":"[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Total Downloads][ico-downloads]][link-downloads]\n\n\u003ca href=\"https://www.buymeacoffee.com/takielias\" target=\"_blank\"\u003e \u003cimg align=\"left\" src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" height=\"50\" width=\"210\" alt=\"takielias\" /\u003e\u003c/a\u003e\n\u003c/a\u003e\n\u003cbr\u003e\u003cbr\u003e\n\n# CodeIgniter WebSocket Library\nCodeIgniter WebSocket library. It allows you to make powerfull realtime applications by using Ratchet ([Socketo.me](http://socketo.me) \u0026 [ratchet_client](https://github.com/romainrg/ratchet_client)) Websocket technology.\n\n## WebSocket Library for Codeigniter 4.x https://github.com/takielias/codeigniter4-websocket\n\nIf you Face any problem you may check CodeIgniter WebSocket Example https://github.com/takielias/codeigniter-websocket-example\n\n## :books: Dependencies\n\n- PHP 5.6+\n- CodeIgniter Framework (3.1.* recommanded)\n- Composer\n- PHP sockets extension enabled\n\n## :beginner: Installation\n\n### :arrow_right: Step 1 : Library installation by Composer\n\nJust by running following command in the folder of your project :\n```sh\ncomposer require takielias/codeigniter-websocket\n```\nDon't forget to include your autoload to CI config file :\n```php\n$config['composer_autoload'] = FCPATH.'vendor/autoload.php';\n```\n### :arrow_right: Step 2 : One command Setup\n\nIf you want Single command installation just Execute the Command in the Project directory\n\n**N.B:** It will make 2 new controllers  Welcome.php and User.php\n```sh\nphp vendor/takielias/codeigniter-websocket/install.php --app_path=application\n```\nHere app_path defines your default Codeigniter Application directory Name\n\n![one click installation](https://user-images.githubusercontent.com/38932580/57182660-74df9a80-6ec3-11e9-8b31-37f3fcbf4ccd.png)\n\n**WOW You made it !!!** :heavy_check_mark: \n\nOpen two pages of your project on following url with different IDs :\n\n`http://localhost/your project directory/index.php/user/index/1`\n\n`http://localhost/your project directory/index.php/user/index/2`\n\n:heavy_exclamation_mark: In this example, **recipient_id** is defined by **user_id**, as you can see, it's the **auth callback** who defines recipient ids.\n\nIf you have something like that, everything is ok for you:\n\n![user_1](https://user-images.githubusercontent.com/38932580/57090224-21851500-6d28-11e9-9321-20d02e146d62.png)\n\n\n![user_2](https://user-images.githubusercontent.com/38932580/57090269-44afc480-6d28-11e9-8ea1-30079a3a47e9.png)\n\nYou can try typing and sending something in each page (see cmd for more logs).\n\n![cmd](https://user-images.githubusercontent.com/38932580/57090313-5abd8500-6d28-11e9-8644-8e0323a36a41.png)\n\n\n#### :arrow_right: Run the Websocket server Manually\nIf you want to enable debug mode type the command bellow in you'r project folder :\n```sh\nphp index.php welcome index\n```\nIf you see the message the message bellow,  you are done (don't close your cmd) !\n\n![First_launch.png](https://user-images.githubusercontent.com/14097222/40981263-d568413a-68da-11e8-9ab2-7b3f7224526e.PNG)\n#### :arrow_right: Test the App\n\n## Broadcast messages with your php App :boom: !\nIf you want to broadcast message with php script or something else you can use library like [textalk/websocket](https://github.com/Textalk/websocket-php) ***(who is included in my composer.json as required library)***\n\n\u003e *Note : The first message is mandatory and always here to perform authentication*\n\n```php\n$client = new Client('ws://0.0.0.0:8282');\n\n$client-\u003esend(json_encode(array('user_id' =\u003e 1, 'message' =\u003e null)));\n$client-\u003esend(json_encode(array('user_id' =\u003e 1, 'message' =\u003e 'Super cool message to myself!')));\n```\n## Authentication \u0026 callbacks :recycle:\nThe library allow you to define some callbacks, here's an example :\n```php\nclass Welcome extends CI_Controller\n{\n    public function index()\n    {\n        // Load package path\n        $this-\u003eload-\u003eadd_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');\n        $this-\u003eload-\u003elibrary('Codeigniter_websocket');\n        $this-\u003eload-\u003eremove_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');\n\n        // Run server\n        $this-\u003ecodeigniter_websocket-\u003eset_callback('auth', array($this, '_auth'));\n        $this-\u003ecodeigniter_websocket-\u003eset_callback('event', array($this, '_event'));\n        $this-\u003ecodeigniter_websocket-\u003erun();\n    }\n\n    public function _auth($datas = null)\n    {\n        // Here you can verify everything you want to perform user login.\n        // However, method must return integer (client ID) if auth succedeed and false if not.\n        return (!empty($datas-\u003euser_id)) ? $datas-\u003euser_id : false;\n    }\n\n    public function _event($datas = null)\n    {\n        // Here you can do everyting you want, each time message is received\n        echo 'Hey ! I\\'m an EVENT callback'.PHP_EOL;\n    }\n}\n```\n\n - **Auth** type callback is called at first message posted from client.\n - **Event** type callback is called on every message posted.\n\n# How to receive response into Codeigniter Controller ?\n\nPlease look at the Welcome.php controller.\n\n\tpublic function index()\n\t{\n\t\t// Load package path\n\t\t$this-\u003eload-\u003eadd_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');\n\t\t$this-\u003eload-\u003elibrary('Codeigniter_websocket');\n\t\t$this-\u003eload-\u003eremove_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');\n\n\t\t// Run server\n\t\t$this-\u003ecodeigniter_websocket-\u003eset_callback('auth', array($this, '_auth'));\n\t\t$this-\u003ecodeigniter_websocket-\u003eset_callback('event', array($this, '_event'));\n\t\t$this-\u003ecodeigniter_websocket-\u003eset_callback('roomleave', array($this, '_roomleave'));\n\t\t$this-\u003ecodeigniter_websocket-\u003erun();\n\t}\n\n\tpublic function _roomleave($data = null)\n\t{\n\t\t// Here you will receive data from the frontend roomleave event trigger.\n\t\techo 'Hey ! I\\'m a room leave EVENT callback' . PHP_EOL;\n\t}\nThe main concept is the callback function.\n\nYou would receive the response into the defined function. You can trigger the event from the front end like below using jQuery\n\n        socket.send(JSON.stringify({\n            'type': 'roomleave',\n            'room_name': targetName,\n            'user_id': \"buzz4rd\"\n        }));\n\nIt would trigger the function below\n\n\n\tpublic function _roomleave($data = null)\n\t{\n\t\t// Here you will receive data from fron tend roomleave event trigger.\n\t\techo 'Hey ! I\\'m a room leave EVENT callback' . PHP_EOL;\n\t}\n\nYou May Check [Room Chat using PHP websocket](https://github.com/takielias/ci-socket-chat). It was built using [this](https://github.com/romainrg/ratchet_client)\n\n## Bugs :bug: or feature :muscle:\nBe free to open an issue or send pull request\n\n## Support on Buy Me A Coffee\nHey dude! Help me out for a cup of ☕!\n\n\u003ca href=\"https://www.buymeacoffee.com/takielias\" target=\"_blank\"\u003e \u003cimg align=\"left\" src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" height=\"50\" width=\"210\" alt=\"takielias\" /\u003e\u003c/a\u003e\n\u003c/a\u003e\n\u003cbr\u003e\u003cbr\u003e\n\n[ico-version]: https://img.shields.io/packagist/v/takielias/codeigniter-websocket.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/takielias/codeigniter-websocket.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/takielias/codeigniter-websocket\n[link-downloads]: https://packagist.org/packages/takielias/codeigniter-websocket\n[link-author]: https://github.com/takielias\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakielias%2Fcodeigniter-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakielias%2Fcodeigniter-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakielias%2Fcodeigniter-websocket/lists"}