{"id":13828624,"url":"https://github.com/pupper/pupper-php","last_synced_at":"2025-07-09T06:32:24.676Z","repository":{"id":57045844,"uuid":"107289198","full_name":"pupper/pupper-php","owner":"pupper","description":"PHP components for Pupper","archived":true,"fork":false,"pushed_at":"2017-12-20T08:36:24.000Z","size":29,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-11T09:25:54.236Z","etag":null,"topics":["php","pupper","react","websockets"],"latest_commit_sha":null,"homepage":"https://pupper.github.io/pupper-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pupper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-17T15:37:37.000Z","updated_at":"2023-01-28T13:18:45.000Z","dependencies_parsed_at":"2022-08-24T03:40:19.629Z","dependency_job_id":null,"html_url":"https://github.com/pupper/pupper-php","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pupper%2Fpupper-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pupper%2Fpupper-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pupper%2Fpupper-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pupper%2Fpupper-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pupper","download_url":"https://codeload.github.com/pupper/pupper-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225492420,"owners_count":17482869,"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","pupper","react","websockets"],"created_at":"2024-08-04T09:02:55.821Z","updated_at":"2024-11-20T08:30:54.773Z","avatar_url":"https://github.com/pupper.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"![d005d89e-ff25-4450-9119-aa56ff0d8949](https://user-images.githubusercontent.com/3274103/31629229-4859fe88-b2b3-11e7-85fb-66c35710f607.png)\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3048eebd495341368703ab58fd5202b4)](https://www.codacy.com/app/bouiboui/pupper-php?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=pupper/pupper-php\u0026utm_campaign=badger)\n![Software License][ico-license] [![SensioLabsInsight](https://insight.sensiolabs.com/projects/38ef8a9c-deb5-41d4-a3f3-432fa411e921/mini.png)](https://insight.sensiolabs.com/projects/38ef8a9c-deb5-41d4-a3f3-432fa411e921)\n\nPupper stands for \"PHP Plus React\" (PPR \u003e Pupper). The goal is to make a Framework that takes the best of both technologies and makes them communicate bi-directionnaly.\n\n[See an example implementation](https://github.com/bouiboui/pupper/tree/master/app)\n\n## Quick start\n\nPupper PHP is based on [Aerys](https://amphp.org/aerys/), a non-blocking PHP application and Websocket framework.\n\nHere is a quick overview of the code to get started.\n\n```php\nuse Pupper\\Pupper\\Event;\n\n// Initiates WebSocket connection\n$websocket = (new Pupper\\Pupper\\WebSocket)\n\n    // Filter allowed clients (optional)\n    -\u003eallowOrigin('https', 'your.domain.com', 443);\n\n    // Defines a callback for 'my_event'\n    -\u003eaddEventListener('my_event', function (Event $event) {\n    \n        // Dispatches to all clients\n        $websocket-\u003ebroadcastEvent(\n            new Event('notify_all', 'Something has happened!');\n        );\n    \n        // Dispatches to the client that triggered the callback\n        return (new Event)\n            -\u003esetName('operation_done')\n            -\u003esetValue('Your value was ' . $event-\u003egetValue());\n\n    });\n\n$router = Aerys\\router()-\u003eroute('GET', '/', Aerys\\websocket($websocket));\n\n// Exposes the websocket to the 1337 port\nreturn (new Aerys\\Host)-\u003euse($router)-\u003eexpose('*', 1337);\n```\n\n## API\n### WebSocket\n\n`WebSocket` is the class that initiates the WebSocket on the PHP side.\n\n**addListener**\n\n`addListener` takes the event name as first parameter, and a callback function as a second parameter. \n\nIf you `return` an `Event`, it will be dispatched to the client that triggered the callback. \n\n```php\nuse Pupper\\Pupper\\Event;\n\n$websocket = (new Pupper\\Pupper\\WebSocket)\n    -\u003eaddEventListener('custom', function (Event $event) {\n        return (new Event)\n            -\u003esetName('custom')\n            -\u003esetValue('From PHP: ' . $event-\u003egetValue());\n    });\n```\n\n**broadcastEvent**\n\n`broadcastEvent` dispatches an event to all the clients.\n```php\nuse Pupper\\Pupper\\Event;\n\n$websocket = (new Pupper\\Pupper\\WebSocket)\n    -\u003eaddEventListener('player_has_joined', function (Event $event) {\n        $websocket-\u003ebroadcastEvent(\n            'player_count_updated',\n            'A new player has joined!'\n        );\n    });\n```\n\n**Client filtering**\n\nSet WebSocket's constructor's protocol, host and port parameters to restrict the access to your websocket .\n\n```php\n$websocket = (new \\Pupper\\WebSocket)-\u003eallowOrigin('https', 'your.domain.com', 80);\n```\n\n\n### Event\n\n`Event` represents an event from the PHP side.\n\n\n**Read**\n\n`Event` has `getName()` and `getValue()` methods to read the event's name and value.\n\n```php\nuse Pupper\\Pupper\\Event;\n\nfunction (Event $event) {\n    echo $event-\u003egetName();\n    echo $event-\u003egetValue();\n});\n```\n\n**Write**\n\n`Event` has `setName()` and `setValue()` methods to write the event's name and value.\n\n```php\nuse Pupper\\Pupper\\Event;\n\n$event = (new Event)\n    -\u003esetName('hello_event')\n    -\u003esetValue('Hello from PHP!');\n```\n\n**Construct**\n\n`Event`'s constructor also accepts the event's name and value as parameters.\n\n```php\nuse Pupper\\Pupper\\Event;\n\n$event = new Event(\n    'hello_event', \n    'Hello from PHP!'\n);\n```\n\n## Credits\n\n- [bouiboui][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nUnlicense. Please see [License File](LICENSE.md) for more information.\n\n[ico-license]: https://img.shields.io/badge/license-Unlicense-brightgreen.svg?style=flat-square\n\n[link-author]: https://github.com/bouiboui\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpupper%2Fpupper-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpupper%2Fpupper-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpupper%2Fpupper-php/lists"}