{"id":14983904,"url":"https://github.com/luzrain/workerman-bundle","last_synced_at":"2025-04-10T19:43:05.365Z","repository":{"id":188065556,"uuid":"676995419","full_name":"luzrain/workerman-bundle","owner":"luzrain","description":"Workerman runtime for symfony applications","archived":false,"fork":false,"pushed_at":"2024-02-15T15:59:24.000Z","size":136,"stargazers_count":27,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T17:21:22.806Z","etag":null,"topics":["symfony-bundle","workerman","workerman-bundle"],"latest_commit_sha":null,"homepage":"","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/luzrain.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}},"created_at":"2023-08-10T13:47:11.000Z","updated_at":"2025-02-19T10:03:39.000Z","dependencies_parsed_at":"2024-12-03T19:33:54.394Z","dependency_job_id":"a481940d-50ca-4ace-8f9d-03457807940a","html_url":"https://github.com/luzrain/workerman-bundle","commit_stats":{"total_commits":73,"total_committers":1,"mean_commits":73.0,"dds":0.0,"last_synced_commit":"2ab200e919e387f3c291d44fb40440a8fcd80c84"},"previous_names":["luzrain/workerman-bundle"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Fworkerman-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Fworkerman-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Fworkerman-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luzrain%2Fworkerman-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luzrain","download_url":"https://codeload.github.com/luzrain/workerman-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248152197,"owners_count":21056263,"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":["symfony-bundle","workerman","workerman-bundle"],"created_at":"2024-09-24T14:08:09.265Z","updated_at":"2025-04-10T19:43:05.344Z","avatar_url":"https://github.com/luzrain.png","language":"PHP","readme":"# Workerman runtime for symfony applications\n![PHP ^8.1](https://img.shields.io/badge/PHP-^8.1-777bb3.svg?style=flat)\n![Symfony ^6.4|^7.0](https://img.shields.io/badge/Symfony-^6.4|^7.0-374151.svg?style=flat)\n[![Tests Status](https://img.shields.io/github/actions/workflow/status/luzrain/workerman-bundle/tests.yaml?branch=master)](../../actions/workflows/tests.yaml)\n\n[Workerman](https://github.com/walkor/workerman) is a high-performance, asynchronous event-driven PHP framework written in pure PHP.  \nThis bundle provides a Workerman integration in Symfony, allowing you to easily create a http server, scheduler and supervisor all in one place.\nThis bundle allows you to replace a traditional web application stack like php-fpm + nginx + cron + supervisord, all written in pure PHP (no Go, no external binaries).\nThe request handler works in an event loop which means the Symfony kernel and the dependency injection container are preserved between requests,\nmaking your application faster with less (or no) code changes.\n\n## Getting started\n### Install composer packages\n```bash\n$ composer require luzrain/workerman-bundle nyholm/psr7\n```\n\n### Enable the bundle\n```php\n\u003c?php\n// config/bundles.php\n\nreturn [\n    // ...\n    Luzrain\\WorkermanBundle\\WorkermanBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n### Configure the bundle\nA minimal configuration might look like this.  \nFor all available options with documentation, see the command output.\n```bash\n$ bin/console config:dump-reference workerman\n```\n\n```yaml\n# config/packages/workerman.yaml\n\nworkerman:\n  servers:\n    - name: 'Symfony webserver'\n      listen: http://0.0.0.0:80\n      processes: 4\n\n  reload_strategy:\n    exception:\n      active: true\n\n    file_monitor:\n      active: true\n```\n\n### Start application\n```bash\n$ APP_RUNTIME=Luzrain\\\\WorkermanBundle\\\\Runtime php public/index.php start\n```\n\n\\* For better performance, Workerman recommends installing the _php-event_ extension.\n\n## Reload strategies\nBecause of the asynchronous nature of the server, the workers reuse loaded resources on each request. This means that in some cases we need to restart workers.  \nFor example, after an exception is thrown, to prevent services from being in an unrecoverable state. Or every time you change the code in the IDE.  \nThere are a few restart strategies that are implemented and can be enabled or disabled depending on the environment.\n\n - **exception**  \n   Reload worker each time that an exception is thrown during the request handling.\n - **max_requests**  \n   Reload worker on every N request to prevent memory leaks.\n - **file_monitor**  \n   Reload all workers each time you change the files**.\n - **always**  \n   Reload worker after each request.\n\n** It is highly recommended to install the _php-inotify_ extension for file monitoring. Without it, monitoring will work in polling mode, which can be very cpu and disk intensive for large projects.\n\nSee all available options for each strategy in the command output.\n```bash\n$ bin/console config:dump-reference workerman reload_strategy\n```\n\n### Implement your own reload strategies\nYou can create reload strategy with your own logic by implementing the RebootStrategyInterface and adding the `workerman.reboot_strategy` tag to the service.\n```php\n\u003c?php\n\nuse Luzrain\\WorkermanBundle\\Reboot\\RebootStrategyInterface;\nuse Symfony\\Component\\DependencyInjection\\Attribute\\AutoconfigureTag;\n\n#[AutoconfigureTag('workerman.reboot_strategy')]\nfinal class TestRebootStrategy implements RebootStrategyInterface\n{\n    public function shouldReboot(): bool\n    {\n        return true;\n    }\n}\n```\n\n## Scheduler\nPeriodic tasks can be configured with attributes or with tags in configuration files.  \nSchedule string can be formatted in several ways:  \n - An integer to define the frequency as a number of seconds. Example: _60_\n - An ISO8601 datetime format. Example: _2023-08-01T01:00:00+08:00_\n - An ISO8601 duration format. Example: _PT1M_\n - A relative date format as supported by DateInterval. Example: _1 minutes_\n - A cron expression**. Example: _*/1 * * * *_\n\n** Note that you need to install the [dragonmantank/cron-expression](https://github.com/dragonmantank/cron-expression) package if you want to use cron expressions as schedule strings\n\n```php\n\u003c?php\n\nuse Luzrain\\WorkermanBundle\\Attribute\\AsTask;\n\n/**\n * Attribute parameters\n * name: Task name\n * schedule: Task schedule in any format\n * method: method to call, __invoke by default\n * jitter: Maximum jitter in seconds that adds a random time offset to the schedule. Use to prevent multiple tasks from running at the same time\n */\n#[AsTask(name: 'My scheduled task', schedule: '1 minutes')]\nfinal class TaskService\n{\n    public function __invoke()\n    {\n        // ...\n    }\n}\n```\n\n## Supervisor\nSupervisor can be configured with attributes or with tags in configuration files.  \nProcesses are kept alive and wake up if one of them dies.\n\n```php\n\u003c?php\n\nuse Luzrain\\WorkermanBundle\\Attribute\\AsProcess;\n\n/**\n * Attribute parameters\n * name: Process name\n * processes: number of processes\n * method: method to call, __invoke by default\n */\n#[AsProcess(name: 'My worker', processes: 1)]\nfinal class ProcessService\n{\n    public function __invoke()\n    {\n        // ...\n    }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluzrain%2Fworkerman-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluzrain%2Fworkerman-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluzrain%2Fworkerman-bundle/lists"}