All Projects → ostark → Craft Async Queue

ostark / Craft Async Queue

Licence: mit
Async Queue Handler for Craft 3

Projects that are alternatives of or similar to Craft Async Queue

Simplemap
A beautifully simple map field type for Craft CMS.
Stars: ✭ 136 (+70%)
Mutual labels:  craftcms, craft, craft3
tablemaker
A user-definable table field type for Craft CMS
Stars: ✭ 39 (-51.25%)
Mutual labels:  craft, craftcms, craft3
Seo
SEO utilities including a unique field type, sitemap & redirect manager
Stars: ✭ 210 (+162.5%)
Mutual labels:  craftcms, craft, craft3
Buttonbox
A collection of utility field types for Craft
Stars: ✭ 94 (+17.5%)
Mutual labels:  craftcms, craft, craft3
padstone
Padstone is a Craft CMS starter kit with a curated configuration, Boilerplate templates, and handpicked plugins.
Stars: ✭ 18 (-77.5%)
Mutual labels:  craft, craftcms, craft3
Craft Preparse Field
Field type that parses twig when an element is saved.
Stars: ✭ 103 (+28.75%)
Mutual labels:  craftcms, craft, craft3
craft-audit
Audit log for Craft 3
Stars: ✭ 18 (-77.5%)
Mutual labels:  craft, craftcms, craft3
Craftcms Docker
Craft3/Craft2 CMS Docker base (Nginx, PHP-FPM 8, PostgreSQL/MariaDB, Redis)
Stars: ✭ 99 (+23.75%)
Mutual labels:  craftcms, craft, craft3
visor
🕶 A simple admin overlay to get to the relevant areas of the Craft CMS control panel.
Stars: ✭ 25 (-68.75%)
Mutual labels:  craft, craftcms, craft3
craft-bulkedit
Bulk edit any set of elements
Stars: ✭ 22 (-72.5%)
Mutual labels:  craft, craftcms, craft3
craft3-collections
Clean up those complex templates with Laravel Collections
Stars: ✭ 24 (-70%)
Mutual labels:  craft, craftcms, craft3
craft-plugin-mix
Helper plugin for Laravel Mix in Craft CMS templates
Stars: ✭ 50 (-37.5%)
Mutual labels:  craft, craftcms, craft3
craft-entry-instructions
A simple fieldtype to add instructions.
Stars: ✭ 16 (-80%)
Mutual labels:  craft, craftcms, craft3
molecule
⚛️ Grab Twig components, CSS and JS files outside the primary template folder
Stars: ✭ 20 (-75%)
Mutual labels:  craft, craftcms, craft3
Craft3 Iconpicker
Craft plugin that provides a new field type that offers end users an easy way to pick an icon from a .woff or .ttf font file. You can easily use ionicons or font awesome icons or any other compatible font file.
Stars: ✭ 15 (-81.25%)
Mutual labels:  craftcms, craft3, plugin
craft-commerce-widgets
Insightful widgets for Craft CMS Commerce stores
Stars: ✭ 33 (-58.75%)
Mutual labels:  craftcms, craft3
craft-recipe
A comprehensive recipe FieldType for Craft CMS that includes metric/imperial conversion, portion calculation, and JSON-LD microdata support
Stars: ✭ 23 (-71.25%)
Mutual labels:  craftcms, craft3
Contact Form
Add a simple contact form to your Craft CMS site.
Stars: ✭ 294 (+267.5%)
Mutual labels:  craftcms, craft3
Craft3 Multi Environment
DEPRECATED Efficient and flexible multi-environment config for Craft CMS
Stars: ✭ 76 (-5%)
Mutual labels:  craftcms, craft3
craft-entriessubset
Craft field type plugin that extends the core Entries field type to give extra settings
Stars: ✭ 27 (-66.25%)
Mutual labels:  craft, craftcms

Async (Background) Queue

Latest Stable Version Total Downloads Monthly Downloads Buy us a tree

With Craft's job queue you can run heavy tasks in the background. Unfortunately, this is not entirely true, when runQueueAutomatically => true (default), the job queue is handled by a ajax (FPM) call. With 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.

Here you can find the initial discussion I started at craftcms/cms.

Sponsor 🐇

Development happens in my free time, but also during working hours. Thanks fortrabbit.com!

Licence 🌳

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank me for my work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Requirements

  • Craft 3
  • Permissions to execute a php binary
  • proc_open()
  • PHP >=7.1 (for PHP 7.0 use ostark/craft-async-queue:1.3.*)

Installation

cd your/craft-project
composer require ostark/craft-async-queue
php craft install/plugin async-queue

If you run into Composer version conflicts:

composer config platform --unset
composer update
php craft migrate/all
composer require ostark/craft-async-queue
php craft install/plugin async-queue

Configuration (optional)

The plugin uses 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:

PHP_BINARY="/usr/local/Cellar/php71/7.1.0_11/bin/php"

By default 2 background processes handle the queue. With the ASYNC_QUEUE_CONCURRENCY ENV var you can modify this behaviour.

# No concurrency
ASYNC_QUEUE_CONCURRENCY=1

# Or max 5 background processes
ASYNC_QUEUE_CONCURRENCY=5

To disable the plugin in certain environments, like on Windows which is not supported yet, set the DISABLE_ASYNC_QUEUE ENV var.

DISABLE_ASYNC_QUEUE=1

Tests

Beside the test suite you can run from the command line with this shortcut: composer tests, you can perform a test in the Craft CP. Navigate to Utilities > Async Queue Test and hit the Run test button.

Events

The 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. By setting useDefaultDecoration to false you prevent this. You have also the ability to modify the command itself.

// Add handler
\yii\base\Event::on(
     \ostark\AsyncQueue\QueueCommand::class,
     \ostark\AsyncQueue\QueueCommand::EVENT_PREPARE_COMMAND,
     function(\ostark\AsyncQueue\Events\QueueCommandEvent $event) {
         $event->useDefaultDecoration = false;
         $event->commandLine = "BEFORE {$event->commandLine} AFTER";
     }
);

Under the hood: Process list

Empty queue (only php-fpm master is running)

$ ps auxf | grep php

root      2953  0.0  0.0 399552 13520 ?        Ss   12:27   0:00 php-fpm: master process (/etc/php/fpm.conf)

New job pushed (php-fpm master + child + /usr/bin/php daemon started)

$ ps auxf | grep php

root      2953  0.0  0.0 399552 13520 ?        Ss   12:27   0:00 php-fpm: master process (/etc/php/fpm.conf)
app       3031  2.2  0.2 718520 45992 ?        S    12:31   0:00  \_ php-fpm: pool www
app       3033  1.2  0.2 280936 32808 ?        S    12:31   0:00 /usr/bin/php craft queue/run
app       3034  0.0  0.0   4460   784 ?        S    12:31   0:00  \_ sh -c /usr/bin/php craft queue/exec "1234" "0" "1"
app       3035  1.2  0.2 280928 32280 ?        S    12:31   0:00      \_ /usr/bin/php craft queue/exec 1234 0 1
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].