Server IP : 172.67.216.182 / Your IP : 172.69.176.30 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/coircraft.com/wp-content/plugins/caldera-forms/vendor/a5hleyrich/wp-queue/ |
Upload File : |
[](https://travis-ci.org/A5hleyRich/wp-queue) [](https://scrutinizer-ci.com/g/A5hleyRich/wp-queue/?branch=master) [](https://packagist.org/packages/a5hleyrich/wp-queue) [](https://packagist.org/packages/a5hleyrich/wp-queue) [](https://packagist.org/packages/a5hleyrich/wp-queue) ## Prerequisites WP_Queue requires PHP __5.3+__. The following database tables need to be created: ``` CREATE TABLE {$wpdb->prefix}queue_jobs ( id bigint(20) NOT NULL AUTO_INCREMENT, job longtext NOT NULL, attempts tinyint(3) NOT NULL DEFAULT 0, reserved_at datetime DEFAULT NULL, available_at datetime NOT NULL, created_at datetime NOT NULL, PRIMARY KEY (id) ``` ``` CREATE TABLE {$wpdb->prefix}queue_failures ( id bigint(20) NOT NULL AUTO_INCREMENT, job longtext NOT NULL, error text DEFAULT NULL, failed_at datetime NOT NULL, PRIMARY KEY (id) ``` Alternatively, you can call the `wp_queue_install_tables()` helper function to install the tables. If using WP_Queue in a plugin you may opt to call the helper from within your `register_activation_hook`. ## Jobs Job classes should extend the `WP_Queue\Job` class and normally only contain a `handle` method which is called when the job is processed by the queue worker. Any data required by the job should be passed to the constructor and assigned to a public property. This data will remain available once the job is retrieved from the queue. Let's look at an example job class: ``` <?php use WP_Queue\Job; class Subscribe_User_Job extends Job { /** * @var int */ public $user_id; /** * Subscribe_User_Job constructor. * * @param int $user_id */ public function __construct( $user_id ) { $this->user_id = $user_id; } /** * Handle job logic. */ public function handle() { $user = get_user_by( 'ID', $this->user_id ); // Process the user... } } ``` ## Dispatching Jobs Jobs can be pushed to the queue like so: ``` wp_queue()->push( new Subscribe_User_Job( 12345 ) ); ``` You can create delayed jobs by passing an optional second parameter to the `push` method. This job will be delayed by 60 minutes: ``` wp_queue()->push( new Subscribe_User_Job( 12345 ), 3600 ); ``` ## Cron Worker Jobs need to be processed by a queue worker. You can start a cron worker like so, which piggy backs onto WP cron: ``` wp_queue()->cron(); ``` You can also specify the number of times a job should be attempted before being marked as a failure. ``` wp_queue()->cron( 3 ); ``` ## Local Development When developing locally you may want jobs processed instantly, instead of them being pushed to the queue. This can be useful for debugging jobs via Xdebug. Add the following filter to use the `sync` connection: ``` add_filter( ‘wp_queue_default_connection’, function() { return ‘sync’; } ); ``` ## License WP Queue is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).