{"id":21352578,"url":"https://github.com/ostark/craft-async-queue","last_synced_at":"2025-04-05T22:08:56.773Z","repository":{"id":24355327,"uuid":"101285113","full_name":"ostark/craft-async-queue","owner":"ostark","description":"Async Queue Handler for Craft 3 and 4","archived":false,"fork":false,"pushed_at":"2024-05-21T10:14:32.000Z","size":1072,"stargazers_count":95,"open_issues_count":5,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T21:05:33.621Z","etag":null,"topics":["craft","craft3","craftcms","craftcms-plugin","plugin"],"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/ostark.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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":"2017-08-24T10:52:37.000Z","updated_at":"2025-01-17T16:58:10.000Z","dependencies_parsed_at":"2024-06-18T15:17:19.196Z","dependency_job_id":"a7b20560-434d-43ff-a73d-006a42e6a247","html_url":"https://github.com/ostark/craft-async-queue","commit_stats":{"total_commits":86,"total_committers":3,"mean_commits":"28.666666666666668","dds":"0.046511627906976716","last_synced_commit":"9e225aa642b955f4bbe8632c768c62d0ac9e1cc5"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostark%2Fcraft-async-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostark%2Fcraft-async-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostark%2Fcraft-async-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostark%2Fcraft-async-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ostark","download_url":"https://codeload.github.com/ostark/craft-async-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406091,"owners_count":20933803,"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":["craft","craft3","craftcms","craftcms-plugin","plugin"],"created_at":"2024-11-22T03:14:11.060Z","updated_at":"2025-04-05T22:08:56.737Z","avatar_url":"https://github.com/ostark.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async (Background) Queue\n\n[![Latest Stable Version](https://poser.pugx.org/ostark/craft-async-queue/v/stable)](https://packagist.org/packages/ostark/craft-async-queue)\n[![Total Downloads](https://poser.pugx.org/ostark/craft-async-queue/downloads)](https://packagist.org/packages/ostark/craft-async-queue)\n[![Monthly Downloads](https://poser.pugx.org/ostark/craft-async-queue/d/monthly)](https://packagist.org/packages/ostark/craft-async-queue)\n[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/ostark/craft-async-queue)\n\nWith Craft's job queue you can run heavy tasks in the background. Unfortunately, this is not entirely true. When `runQueueAutomatically =\u003e true` (default), the job queue is handled by a ajax (FPM) call.\nWith many jobs in the queue and limited PHP-FPM processes this can break your site. This plugin replaces Craft's default queue handler and moves queue execution to a non-blocking background process. The command `craft queue/run` gets executed right after you push a job to the queue. \n\n[Here](https://github.com/craftcms/cms/issues/1952) you can find the initial discussion I started at `craftcms/cms`.\n\n## Sponsor 🐇\n\nDevelopment happens in my free time, but also during working hours. Thanks [fortrabbit.com](https://www.fortrabbit.com/craft-hosting)!\n\n## Licence 🌳           \n\nThis package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/ostark/craft-async-queue) to thank me for my work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats. \n\n## Requirements\n\n* Craft 3 or 4\n* Permissions to execute a php binary\n* proc_open()\n* **PHP \u003e=7.1** (for PHP 7.0 use `ostark/craft-async-queue:1.3.*`)\n\n## Installation\n\n```shell\ncd your/craft-project\ncomposer require ostark/craft-async-queue\nphp craft install/plugin async-queue\n```\n\nIf you run into Composer version conflicts:\n```\ncomposer config platform --unset\ncomposer update\nphp craft migrate/all\ncomposer require ostark/craft-async-queue\nphp craft install/plugin async-queue\n```\n\n\n## Configuration (optional)\n\nThe plugin uses [symfony/process](https://github.com/symfony/process) to execute the `php` binary. Usually the binary is located in `/usr/bin/`, but other common locations are auto detected as well. With the ENV var `PHP_BINARY` you can explicitly set the path, e.g. in your .env file like this:\n```\nPHP_BINARY=\"/usr/local/Cellar/php71/7.1.0_11/bin/php\"\n```\n\n\nBy default `1` background process handles the queue. With the `ASYNC_QUEUE_CONCURRENCY` ENV var you can modify this behaviour.\n```\n# No concurrency\nASYNC_QUEUE_CONCURRENCY=1\n\n# Or max 5 background processes\nASYNC_QUEUE_CONCURRENCY=5\n```\n\nTo disable the plugin in certain environments, like on Windows which is not supported yet, set the `DISABLE_ASYNC_QUEUE` ENV var.\n```\nDISABLE_ASYNC_QUEUE=1\n```\n\nNote that the plugin will overwrite the `runQueueAutomatically` setting with Craft CMS. No configurartion required.\n\n\n## Tests\n\nBeside the test suite you can run from the command line with this shortcut: `composer tests`, you can perform a test in the Craft CP.\nNavigate to `Utilities` \u003e `Async Queue Test` and hit the `Run test` button. \n\n\n## Events\n\nThe command that runs in the background is basically `php craft queue/run`, however we add some linux specific syntax that executes the command in a non-blocking way.\nBy setting `useDefaultDecoration` to `false` you prevent this. You have also the ability to modify the command itself. \n\n```\n// Add handler\n\\yii\\base\\Event::on(\n     \\ostark\\AsyncQueue\\QueueCommand::class,\n     \\ostark\\AsyncQueue\\QueueCommand::EVENT_PREPARE_COMMAND,\n     function(\\ostark\\AsyncQueue\\Events\\QueueCommandEvent $event) {\n         $event-\u003euseDefaultDecoration = false;\n         $event-\u003ecommandLine = \"BEFORE {$event-\u003ecommandLine} AFTER\";\n     }\n);\n```\n\n\n\n\n## Under the hood: Process list\n\n**Empty queue** (only php-fpm master is running)\n```\n$ ps auxf | grep php\n\nroot      2953  0.0  0.0 399552 13520 ?        Ss   12:27   0:00 php-fpm: master process (/etc/php/fpm.conf)\n````\n\n**New job pushed** (php-fpm master + child + /usr/bin/php daemon started)\n```\n$ ps auxf | grep php\n\nroot      2953  0.0  0.0 399552 13520 ?        Ss   12:27   0:00 php-fpm: master process (/etc/php/fpm.conf)\napp       3031  2.2  0.2 718520 45992 ?        S    12:31   0:00  \\_ php-fpm: pool www\napp       3033  1.2  0.2 280936 32808 ?        S    12:31   0:00 /usr/bin/php craft queue/run\napp       3034  0.0  0.0   4460   784 ?        S    12:31   0:00  \\_ sh -c /usr/bin/php craft queue/exec \"1234\" \"0\" \"1\"\napp       3035  1.2  0.2 280928 32280 ?        S    12:31   0:00      \\_ /usr/bin/php craft queue/exec 1234 0 1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fostark%2Fcraft-async-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fostark%2Fcraft-async-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fostark%2Fcraft-async-queue/lists"}