├── phpunit.xml
├── portkey.json
├── system-tests
├── gearman
│ ├── test-worker.php
│ └── test-client.php
└── rabbitmq
│ ├── test-client.php
│ └── test-worker.php
├── .gitignore
├── tests
├── WpMinions
│ ├── Cron
│ │ ├── WorkerTest.php
│ │ └── ClientTest.php
│ ├── PluginTest.php
│ └── Gearman
│ │ ├── WorkerTest.php
│ │ └── ClientTest.php
├── bootstrap.php
├── WpMinionsRunnerTest.php
└── WpMinionsTest.php
├── .travis.yml
├── includes
└── WpMinions
│ ├── Cron
│ ├── Worker.php
│ └── Client.php
│ ├── Worker.php
│ ├── Client.php
│ ├── RabbitMQ
│ ├── Client.php
│ ├── Connection.php
│ └── Worker.php
│ ├── Gearman
│ ├── Client.php
│ └── Worker.php
│ └── Plugin.php
├── autoload.php
├── composer.json
├── wp-minions.php
├── wp-minions-runner.php
├── CHANGELOG.md
├── bin
└── install-wp-tests.sh
├── readme.md
├── LICENSE.md
└── composer.lock
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | tests
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/portkey.json:
--------------------------------------------------------------------------------
1 | {
2 | "includes/WpMinions/*.php": {
3 | "type": "plugin",
4 | "test": "tests/WpMinions/%sTest.php"
5 | },
6 | "tests/WpMinions/*Test.php": {
7 | "type": "test",
8 | "alternate": "includes/WpMinions/%s.php"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/system-tests/gearman/test-worker.php:
--------------------------------------------------------------------------------
1 | addServer();
4 | $worker->addFunction( "reverse", "my_reverse_function" );
5 | while ( $worker->work() );
6 |
7 | function my_reverse_function( $job ) {
8 | return strrev( $job->workload() );
9 | }
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Version Control
2 | .svn
3 |
4 | # OS
5 | .DS_Store
6 | Thumbs.db
7 |
8 | # IDEs
9 | .buildpath
10 | .project
11 | .settings/
12 | .build/
13 | .idea/
14 | nbproject/
15 | .editorconfig
16 |
17 | # Compass/SASS/SCSS
18 | .sass-cache
19 |
20 | # Other
21 | node_modules
22 |
23 | /vendor/
24 | /release/
25 | tags
26 |
--------------------------------------------------------------------------------
/system-tests/gearman/test-client.php:
--------------------------------------------------------------------------------
1 | addServer();
4 |
5 | // Ensure we have compatibility with php7 and older versions of php
6 | if ( method_exists( $client, 'doNormal' ) ) {
7 | print $client->doNormal( "reverse", $argv[1] ) . "\n";
8 | } else {
9 | print $client->do( "reverse", $argv[1] ) . "\n";
10 | }
11 |
--------------------------------------------------------------------------------
/tests/WpMinions/Cron/WorkerTest.php:
--------------------------------------------------------------------------------
1 | worker = new Worker();
13 | }
14 |
15 | function test_it_can_be_registered() {
16 | $actual = $this->worker->register();
17 | $this->assertTrue( $actual );
18 | }
19 |
20 | function test_it_can_start_working_on_work() {
21 | $actual = $this->worker->work();
22 | $this->assertTrue( $actual );
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/system-tests/rabbitmq/test-client.php:
--------------------------------------------------------------------------------
1 | channel();
10 |
11 | $channel->queue_declare( 'hello', false, false, false, false );
12 |
13 | $msg = new AMQPMessage( 'Hello World!' );
14 | $channel->basic_publish( $msg, '', 'hello' );
15 |
16 | echo " [x] Sent 'Hello World!'\n";
17 |
18 |
19 | $channel->close();
20 | $connection->close();
21 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | client = new Client();
13 | }
14 |
15 | function test_it_can_be_registered() {
16 | $actual = $this->client->register();
17 | $this->assertTrue( $actual );
18 | }
19 |
20 | function test_it_creates_cron_event_on_add() {
21 | $actual = $this->client->add( 'cron_action_a' );
22 | $this->assertTrue( $actual );
23 |
24 | $next_event = wp_next_scheduled( 'cron_action_a', array( array() ) );
25 | $this->assertEquals( time(), $next_event, '', 1000 );
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/includes/WpMinions/Worker.php:
--------------------------------------------------------------------------------
1 | channel();
8 |
9 | $channel->queue_declare('hello', false, false, false, false);
10 |
11 | echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
12 |
13 | $callback = function( $msg ) {
14 | echo " [x] Received ", $msg->body, "\n";
15 | };
16 |
17 | $channel->basic_consume( 'hello', '', false, true, false, false, $callback );
18 |
19 | while( count( $channel->callbacks ) ) {
20 | $channel->wait();
21 | }
22 |
23 | $channel->close();
24 | $connection->close();
25 |
--------------------------------------------------------------------------------
/autoload.php:
--------------------------------------------------------------------------------
1 | assertTrue( function_exists( 'wp_minions_autoload' ) );
17 | }
18 |
19 | function test_it_can_autoload_classes() {
20 | spl_autoload_register( 'wp_minions_autoload', false, true );
21 |
22 | $klass = new \WpMinions\Plugin();
23 | $this->assertInstanceOf( '\WpMinions\Plugin', $klass );
24 | }
25 |
26 | function test_it_will_execute_a_job_on_run() {
27 | $mock = \Mockery::mock()
28 | ->shouldReceive( 'register' )
29 | ->andReturn( true )
30 | ->shouldReceive( 'work' )
31 | ->with()
32 | ->once()
33 | ->andReturn( true )
34 | ->getMock();
35 |
36 | $plugin = \WpMinions\Plugin::get_instance();
37 | $plugin->config_prefix = 'B' . uniqid();
38 | $plugin->worker = $mock;
39 |
40 | $actual = wp_minions_runner();
41 | $this->assertEquals( 0, $actual );
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/tests/WpMinionsTest.php:
--------------------------------------------------------------------------------
1 | assertTrue( function_exists( 'wp_minions_autoload' ) );
17 | }
18 |
19 | function test_it_can_initialize_the_plugin() {
20 | wp_async_task_init();
21 |
22 | $plugin = \WpMinions\Plugin::get_instance();
23 | $this->assertTrue( $plugin->did_enable );
24 | }
25 |
26 | function test_it_can_add_job_to_client_object() {
27 | $mock = \Mockery::mock()
28 | ->shouldReceive( 'register' )
29 | ->atMost(1)
30 | ->shouldReceive( 'addServer' )
31 | ->atMost(1)
32 | ->andReturn( true )
33 | ->shouldReceive( 'add' )
34 | ->with( 'action_b', array( 1, 2, 3 ), 'low' )
35 | ->once()
36 | ->andReturn( true )
37 | ->getMock();
38 |
39 | $plugin = \WpMinions\Plugin::get_instance();
40 | $plugin->config_prefix = 'C' . uniqid();
41 | $plugin->client = $mock;
42 |
43 | $actual = wp_async_task_add( 'action_b', array( 1, 2, 3 ), 'low' );
44 | $this->assertTrue( $actual );
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/includes/WpMinions/RabbitMQ/Client.php:
--------------------------------------------------------------------------------
1 | connection ) {
34 | return $this->connection;
35 | }
36 |
37 | try {
38 | $this->connection = new Connection();
39 | } catch ( \Exception $e ) {
40 | return false;
41 | }
42 |
43 | return $this->connection;
44 | }
45 |
46 | /**
47 | * Adds a Job to the libGearman Client's Queue.
48 | *
49 | * @param string $hook The action hook name for the job
50 | * @param array $args Optional arguments for the job
51 | * @param string $priority Optional priority of the job
52 | * @return bool true or false depending on the Client
53 | */
54 | public function add( $hook, $args = array(), $priority = 'normal' ) {
55 | if ( ! $this->connect() ) {
56 | return false;
57 | }
58 |
59 | $job_data = array(
60 | 'hook' => $hook,
61 | 'args' => $args,
62 | 'blog_id' => get_current_blog_id(),
63 | );
64 |
65 | $message = new \PhpAmqpLib\Message\AMQPMessage(
66 | json_encode( $job_data ) );
67 |
68 | $this->connection->get_channel()->basic_publish( $message, '', 'wordpress' );
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/wp-minions.php:
--------------------------------------------------------------------------------
1 | add( $hook, $args, $priority );
35 | }
36 |
37 | function wp_async_task_init() {
38 | wp_minions_autoloader();
39 |
40 | $plugin = \WpMinions\Plugin::get_instance();
41 | $plugin->enable();
42 |
43 | $GLOBALS['wp_async_task'] = $plugin;
44 | }
45 |
46 | add_action( 'plugins_loaded', function() {
47 | global $wp_async_task;
48 |
49 | if ( class_exists( 'Debug_Bar_Extender' ) ) {
50 | Debug_Bar_Extender::instance()->trace_var( $wp_async_task );
51 | }
52 | });
53 |
54 | add_action( 'plugins_loaded', function() {
55 | // Init
56 | if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
57 | wp_async_task_init();
58 | }
59 | }, 9 );
60 |
61 |
--------------------------------------------------------------------------------
/wp-minions-runner.php:
--------------------------------------------------------------------------------
1 | enable();
24 |
25 | return $plugin->run();
26 | }
27 |
28 | function wp_minions_autoloader_file() {
29 | if ( file_exists( __DIR__ . '/autoload.php' ) ) {
30 | return __DIR__ . '/autoload.php';
31 | } else if ( file_exists( __DIR__ . '/wp-content/plugins/wp-minions/autoload.php' ) ) {
32 | return __DIR__ . '/wp-content/plugins/wp-minions/autoload.php';
33 | } else if ( defined( 'WP_MINIONS_DIR' ) ) {
34 | return WP_MINIONS_DIR . '/autoload.php';
35 | } else {
36 | error_log( 'WP Minions Fatal Error - Cannot find autoload.php' );
37 | return false;
38 | }
39 | }
40 |
41 | if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
42 | ignore_user_abort( true );
43 |
44 | if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_ASYNC' ) ) {
45 | die();
46 | }
47 |
48 | define( 'DOING_ASYNC', true );
49 |
50 | if ( ! defined( 'ABSPATH' ) ) {
51 | /** Set up WordPress environment - using SCRIPT_FILENAME so that this file works even if its a symlink! */
52 | if ( ! file_exists( dirname( $_SERVER["SCRIPT_FILENAME"] ) . '/wp-load.php' ) ) {
53 | error_log(
54 | 'WP Minions Fatal Error - Cannot find wp-load.php'
55 | );
56 | }
57 |
58 | require_once( dirname( $_SERVER["SCRIPT_FILENAME"] ) . '/wp-load.php' );
59 | }
60 |
61 | wp_minions_runner();
62 | }
63 |
--------------------------------------------------------------------------------
/includes/WpMinions/RabbitMQ/Connection.php:
--------------------------------------------------------------------------------
1 | 'localhost',
24 | 'port' => 5672,
25 | 'username' => 'guest',
26 | 'password' => 'guest',
27 | 'vhost' => '/',
28 | ) );
29 |
30 | $this->connection = new \PhpAmqpLib\Connection\AMQPStreamConnection( $rabbitmq_server['host'], $rabbitmq_server['port'], $rabbitmq_server['username'], $rabbitmq_server['password'], $rabbitmq_server['vhost'] );
31 | $this->channel = $this->connection->channel();
32 |
33 | $rabbitmq_declare_passive_filter = apply_filters( 'wp_minion_rabbitmq_declare_passive_filter', false );
34 | $rabbitmq_declare_durable_filter = apply_filters( 'wp_minion_rabbitmq_declare_durable_filter', true );
35 | $rabbitmq_declare_exclusive_filter = apply_filters( 'wp_minion_rabbitmq_declare_exclusive_filter', false );
36 | $rabbitmq_declare_autodelete_filter = apply_filters( 'wp_minion_rabbitmq_declare_autodelete_filter', false );
37 |
38 | $this->channel->queue_declare( 'wordpress', $rabbitmq_declare_passive_filter, $rabbitmq_declare_durable_filter, $rabbitmq_declare_exclusive_filter, $rabbitmq_declare_autodelete_filter );
39 |
40 | add_action( 'shutdown', array( $this, 'shutdown' ) );
41 | } else {
42 | throw new \Exception( 'Could not create connection.' );
43 | }
44 | }
45 |
46 | /**
47 | * Return connection channel
48 | *
49 | * @return \PhpAmqpLib\Channel\AMQPChannel
50 | */
51 | public function get_channel() {
52 | return $this->channel;
53 | }
54 |
55 | /**
56 | * Close connection and channel if they are created
57 | */
58 | public function shutdown() {
59 | if ( empty( $this->connection ) || empty( $this->channel ) ) {
60 | return;
61 | }
62 |
63 | $this->channel->close();
64 | $this->connection->close();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file, per [the Keep a Changelog standard](http://keepachangelog.com/), starting with 2.0.1. This project adheres to [Semantic Versioning](http://semver.org/).
4 |
5 | ## [Unreleased]
6 | ### Added
7 | - HHVM compatibility
8 | - Support for RabbitMQ vhost and docs
9 |
10 | ### Fixed
11 | - Hostname from localh1ost to localhost
12 |
13 | ## [4.1.0] - 2018-11-05
14 | ### Added
15 | - Filters for rabbitmq queue options
16 | - Options for rabbitmq vhost. Defaults to `/`
17 |
18 | ### Fixed
19 | - Fixes php-amqplib at 2.8.0
20 |
21 | ## [4.0.0] - 2018-07-06
22 | ### Fixed
23 | - Bug with the WP Cron client where $args were passed to callback functions as individual callback args, instead of as a single array as intended.
24 |
25 | ## [3.0.0] - 2017-07-06
26 | ### Changed
27 | - Renamed from WP Gears to WP Minions, to better reflect that this is designed to be used with any job queue backend - not just Gearman
28 |
29 | ### Fixed
30 | - Ensure unit test suite is compatible with latest versions of PHP and WordPress
31 |
32 | ## [2.1.0] - 2016-05-31
33 | ### Added
34 | - `wp_async_task_after_work` action after the gearman worker finishes working
35 | - Include instance of `GearmanJob` in action hooks
36 |
37 | ### Fixed
38 | - Clarify configuration instructions for Gearman on Ubuntu
39 | - Don't cache blog ID on the gearman client class to fix issues when adding jobs on multiple blogs
40 |
41 | ## [2.0.1] - 2016-05-14
42 | ### Added
43 | - Changelog
44 |
45 | ### Fixed
46 | - Fix fatal error when Gearman unable to connect to gearman servers
47 |
48 | ## [2.0.0] - 2016-01-21
49 | ### Added
50 | - PHPUnit tests
51 | - Build status indicator
52 |
53 | ## [1.0.0] - 2015-10-23
54 | - Initial release
55 |
56 | [Unreleased]: https://github.com/10up/WP-Minions/compare/4.0.0...master
57 | [4.1.0]: https://github.com/10up/WP-Minions/compare/4.0.0...4.1.0
58 | [4.0.0]: https://github.com/10up/WP-Minions/compare/3.0.0...4.0.0
59 | [3.0.0]: https://github.com/10up/WP-Minions/compare/2.1.0...3.0.0
60 | [2.1.0]: https://github.com/10up/WP-Minions/compare/2.0.1...2.1.0
61 | [2.0.1]: https://github.com/10up/WP-Minions/compare/2.0.0...2.0.1
62 | [2.0.0]: https://github.com/10up/WP-Minions/compare/1.0.0...2.0.0
63 | [1.0.0]: https://github.com/10up/WP-Minions/releases/tag/1.0.0
64 |
--------------------------------------------------------------------------------
/includes/WpMinions/RabbitMQ/Worker.php:
--------------------------------------------------------------------------------
1 | connection ) {
26 | return $this->connection;
27 | }
28 |
29 | try {
30 | $this->connection = new Connection();
31 | } catch ( \Exception $e ) {
32 | return false;
33 | }
34 |
35 | return $this->connection;
36 | }
37 |
38 | public function register() {
39 | // Do nothing
40 | }
41 |
42 | public function work() {
43 | if ( ! $this->connect() ) {
44 | return false;
45 | }
46 |
47 | $this->connection->get_channel()->basic_consume( 'wordpress', '', false, true, false, false, function( $message ) {
48 | try {
49 | $job_data = json_decode( $message->body, true );
50 | $hook = $job_data['hook'];
51 | $args = $job_data['args'];
52 |
53 | if ( function_exists( 'is_multisite' ) && is_multisite() && $job_data['blog_id'] ) {
54 | $blog_id = $job_data['blog_id'];
55 |
56 | if ( get_current_blog_id() !== $blog_id ) {
57 | switch_to_blog( $blog_id );
58 | $switched = true;
59 | } else {
60 | $switched = false;
61 | }
62 | } else {
63 | $switched = false;
64 | }
65 |
66 | do_action( 'wp_async_task_before_job', $hook, $message );
67 | do_action( 'wp_async_task_before_job_' . $hook, $message );
68 |
69 | do_action( $hook, $args, $message );
70 |
71 | do_action( 'wp_async_task_after_job', $hook, $message );
72 | do_action( 'wp_async_task_after_job_' . $hook, $message );
73 |
74 | $result = true;
75 | } catch ( \Exception $e ) {
76 | error_log(
77 | 'RabbitMQWorker->do_job failed: ' . $e->getMessage()
78 | );
79 | $result = false;
80 | }
81 |
82 | if ( $switched ) {
83 | restore_current_blog();
84 | }
85 | } );
86 |
87 | while ( count( $this->connection->get_channel()->callbacks ) ) {
88 | $this->connection->get_channel()->wait();
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/bin/install-wp-tests.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | if [ $# -lt 3 ]; then
4 | echo "usage: $0 [db-host] [wp-version]"
5 | exit 1
6 | fi
7 |
8 | DB_NAME=$1
9 | DB_USER=$2
10 | DB_PASS=$3
11 | DB_HOST=${4-localhost}
12 | WP_VERSION=${5-latest}
13 |
14 | WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15 | WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
16 |
17 | download() {
18 | if [ `which curl` ]; then
19 | curl -s "$1" > "$2";
20 | elif [ `which wget` ]; then
21 | wget -nv -O "$2" "$1"
22 | fi
23 | }
24 |
25 | if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26 | WP_TESTS_TAG="tags/$WP_VERSION"
27 | elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
28 | WP_TESTS_TAG="trunk"
29 | else
30 | # http serves a single offer, whereas https serves multiple. we only want one
31 | download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
32 | grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
33 | LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
34 | if [[ -z "$LATEST_VERSION" ]]; then
35 | echo "Latest WordPress version could not be found"
36 | exit 1
37 | fi
38 | WP_TESTS_TAG="tags/$LATEST_VERSION"
39 | fi
40 |
41 | set -ex
42 |
43 | install_wp() {
44 |
45 | if [ -d $WP_CORE_DIR ]; then
46 | return;
47 | fi
48 |
49 | mkdir -p $WP_CORE_DIR
50 |
51 | if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
52 | mkdir -p /tmp/wordpress-nightly
53 | download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
54 | unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
55 | mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
56 | else
57 | if [ $WP_VERSION == 'latest' ]; then
58 | local ARCHIVE_NAME='latest'
59 | else
60 | local ARCHIVE_NAME="wordpress-$WP_VERSION"
61 | fi
62 | download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
63 | tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
64 | fi
65 |
66 | download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
67 | }
68 |
69 | install_test_suite() {
70 | # portable in-place argument for both GNU sed and Mac OSX sed
71 | if [[ $(uname -s) == 'Darwin' ]]; then
72 | local ioption='-i .bak'
73 | else
74 | local ioption='-i'
75 | fi
76 |
77 | # set up testing suite if it doesn't yet exist
78 | if [ ! -d $WP_TESTS_DIR ]; then
79 | # set up testing suite
80 | mkdir -p $WP_TESTS_DIR
81 | svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
82 | fi
83 |
84 | if [ ! -f wp-tests-config.php ]; then
85 | download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
86 | sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
87 | sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
88 | sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
89 | sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
90 | sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
91 | fi
92 |
93 | }
94 |
95 | install_db() {
96 | # parse DB_HOST for port or socket references
97 | local PARTS=(${DB_HOST//\:/ })
98 | local DB_HOSTNAME=${PARTS[0]};
99 | local DB_SOCK_OR_PORT=${PARTS[1]};
100 | local EXTRA=""
101 |
102 | if ! [ -z $DB_HOSTNAME ] ; then
103 | if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
104 | EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
105 | elif ! [ -z $DB_SOCK_OR_PORT ] ; then
106 | EXTRA=" --socket=$DB_SOCK_OR_PORT"
107 | elif ! [ -z $DB_HOSTNAME ] ; then
108 | EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
109 | fi
110 | fi
111 |
112 | # create database
113 | mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
114 | }
115 |
116 | install_wp
117 | install_test_suite
118 | install_db
119 |
--------------------------------------------------------------------------------
/includes/WpMinions/Gearman/Client.php:
--------------------------------------------------------------------------------
1 | get_gearman_client();
33 |
34 | if ( $client !== false ) {
35 | $servers = $this->get_servers();
36 |
37 | try {
38 | if ( empty( $servers ) ) {
39 | return $client->addServer();
40 | } else {
41 | return $client->addServers( implode( ',', $servers ) );
42 | }
43 | } catch ( \GearmanException $e ) {
44 | $servers = implode( ',', $servers );
45 |
46 | if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
47 | error_log( "Fatal Gearman Error: Failed to register servers ($servers)" );
48 | error_log( " Cause: " . $e->getMessage() );
49 | }
50 |
51 | return false;
52 | }
53 | } else {
54 | return false;
55 | }
56 | }
57 |
58 | /**
59 | * Adds a Job to the libGearman Client's Queue.
60 | *
61 | * @param string $hook The action hook name for the job
62 | * @param array $args Optional arguments for the job
63 | * @param string $priority Optional priority of the job
64 | * @return bool true or false depending on the Client
65 | */
66 | public function add( $hook, $args = array(), $priority = 'normal' ) {
67 | $job_data = array(
68 | 'hook' => $hook,
69 | 'args' => $args,
70 | 'blog_id' => $this->get_blog_id(),
71 | );
72 |
73 | $client = $this->get_gearman_client();
74 |
75 | if ( $client !== false ) {
76 | $payload = json_encode( $job_data );
77 | $method = $this->get_background_method( $priority );
78 | $group = $this->get_async_group();
79 | $callable = array( $client, $method );
80 |
81 | return call_user_func( $callable, $group, $payload );
82 | } else {
83 | return false;
84 | }
85 | }
86 |
87 | /* Helpers */
88 | /**
89 | * Returns the libGearman function to use based on the specified
90 | * priority.
91 | *
92 | * @param string $priority low, normal or high
93 | * @return string The corresponding method name
94 | */
95 | function get_background_method( $priority ) {
96 | switch( strtolower( $priority ) ) {
97 | case 'high':
98 | $method = 'doHighBackground';
99 | break;
100 |
101 | case 'low':
102 | $method = 'doLowBackground';
103 | break;
104 |
105 | case 'normal':
106 | default:
107 | $method = 'doBackground';
108 | break;
109 | }
110 |
111 | return $method;
112 | }
113 |
114 | /**
115 | * The Function Group used to split libGearman functions on a
116 | * multi-network install.
117 | *
118 | * @return string The prefixed group name
119 | */
120 | function get_async_group() {
121 | $key = '';
122 |
123 | if ( defined( 'WP_ASYNC_TASK_SALT' ) ) {
124 | $key .= WP_ASYNC_TASK_SALT . ':';
125 | }
126 |
127 | $key .= 'WP_Async_Task';
128 |
129 | return $key;
130 | }
131 |
132 | /**
133 | * The Gearman Servers to connect to as defined in wp-config.php.
134 | *
135 | * If absent the default server will be used.
136 | *
137 | * @return array The list of servers for this Worker.
138 | */
139 | function get_servers() {
140 | if ( is_null( $this->gearman_servers ) ) {
141 | global $gearman_servers;
142 |
143 | if ( ! empty( $gearman_servers ) ) {
144 | $this->gearman_servers = $gearman_servers;
145 | } else {
146 | $this->gearman_servers = array();
147 | }
148 | }
149 |
150 | return $this->gearman_servers;
151 | }
152 |
153 | /**
154 | * Builds the libGearman Client Instance if the extension is
155 | * installed. Once created returns the previous instance without
156 | * reinitialization.
157 | *
158 | * @return GearmanClient|false An instance of GearmanClient
159 | */
160 | function get_gearman_client() {
161 | if ( is_null( $this->gearman_client ) ) {
162 | if ( class_exists( '\GearmanClient' ) ) {
163 | $this->gearman_client = new \GearmanClient();
164 | } else {
165 | $this->gearman_client = false;
166 | }
167 | }
168 |
169 | return $this->gearman_client;
170 | }
171 |
172 | /**
173 | * Caches and returns the current blog id for adding to the Job meta
174 | * data. False if not a multisite install.
175 | *
176 | * @return int|false The current blog ids id.
177 | */
178 | function get_blog_id() {
179 | return function_exists( 'is_multisite' ) && is_multisite() ? get_current_blog_id() : false;
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/tests/WpMinions/PluginTest.php:
--------------------------------------------------------------------------------
1 | plugin = new Plugin();
13 | $this->plugin->config_prefix = 'A' . uniqid();
14 | }
15 |
16 | function tearDown() {
17 | \Mockery::close();
18 | }
19 |
20 | function test_it_has_a_singleton_instance() {
21 | $instance1 = Plugin::get_instance();
22 | $instance2 = Plugin::get_instance();
23 |
24 | $this->assertSame( $instance1, $instance2 );
25 | }
26 |
27 | function test_it_does_not_recreate_client() {
28 | $client1 = $this->plugin->get_client();
29 | $client2 = $this->plugin->get_client();
30 |
31 | $this->assertSame( $client1, $client2 );
32 | }
33 |
34 | function test_it_does_not_recreate_worker() {
35 | $worker1 = $this->plugin->get_worker();
36 | $worker2 = $this->plugin->get_worker();
37 |
38 | $this->assertSame( $worker1, $worker2 );
39 | }
40 |
41 | function test_it_will_execute_one_job_per_worker_by_default() {
42 | $actual = $this->plugin->get_jobs_per_worker();
43 | $this->assertEquals( 1, $actual );
44 | }
45 |
46 | function test_it_will_execute_specified_jobs_per_worker() {
47 | $this->plugin->config_prefix = 'A';
48 | define( 'A_JOBS_PER_WORKER', 50 );
49 |
50 | $actual = $this->plugin->get_jobs_per_worker();
51 | $this->assertEquals( 50, $actual );
52 | }
53 |
54 | function test_it_will_use_a_custom_client_class_if_defined() {
55 | $mock = \Mockery::mock( '\WpMinions\Client' );
56 | $this->plugin->config_prefix = 'B';
57 | define( 'B_CLIENT_CLASS', get_class( $mock ) );
58 |
59 | $actual = $this->plugin->build_client();
60 | $this->assertInstanceOf( get_class( $mock ), $actual );
61 | }
62 |
63 | function test_it_will_use_a_custom_worker_class_if_defined() {
64 | $mock = \Mockery::mock( '\WpMinions\Worker' );
65 | $this->plugin->config_prefix = 'C';
66 | define( 'C_WORKER_CLASS', get_class( $mock ) );
67 |
68 | $actual = $this->plugin->build_worker();
69 | $this->assertInstanceOf( get_class( $mock ), $actual );
70 | }
71 |
72 | function test_it_will_build_a_gearman_client_if_gearman_is_present() {
73 | if ( class_exists( '\GearmanClient' ) ) {
74 | $klass = '\GearmanClient';
75 | $actual = $this->plugin->build_client();
76 |
77 | $this->assertInstanceOf(
78 | '\WpMinions\Gearman\Client', $actual
79 | );
80 | }
81 | }
82 |
83 | function test_it_will_build_a_gearman_worker_if_gearman_is_absent() {
84 | if ( class_exists( '\GearmanWorker' ) ) {
85 | $klass = '\GearmanWorker';
86 | $actual = $this->plugin->build_worker();
87 | $this->assertInstanceOf(
88 | '\WpMinions\Gearman\Worker', $actual
89 | );
90 | }
91 | }
92 |
93 | function test_it_will_build_a_cron_client_if_gearman_is_missing() {
94 | if ( ! class_exists( '\GearmanClient' ) ) {
95 | $actual = $this->plugin->build_client();
96 | $this->assertInstanceOf(
97 | '\WpMinions\Cron\Client', $actual
98 | );
99 | }
100 | }
101 |
102 | function test_it_will_build_a_cron_worker_if_gearman_is_missing() {
103 | if ( ! class_exists( '\GearmanWorker' ) ) {
104 | $actual = $this->plugin->build_worker();
105 | $this->assertInstanceOf(
106 | '\WpMinions\Cron\Worker', $actual
107 | );
108 | }
109 | }
110 |
111 | function test_it_can_pass_jobs_to_client() {
112 | $mock = \Mockery::mock()
113 | ->shouldReceive( 'add' )
114 | ->with( 'action_a', array( 1, 2, 3 ), 'high' )
115 | ->once()
116 | ->andReturn( true )
117 | ->getMock();
118 |
119 | $this->plugin->client = $mock;
120 | $actual = $this->plugin->add( 'action_a', array( 1, 2, 3 ), 'high' );
121 | $this->assertTrue( $actual );
122 | }
123 |
124 | function test_it_will_execute_one_worker_and_exit_by_default() {
125 | $mock = \Mockery::mock()
126 | ->shouldReceive( 'work' )
127 | ->with()
128 | ->once()
129 | ->andReturn( true )
130 | ->getMock();
131 |
132 | $this->plugin->worker = $mock;
133 |
134 | $actual = $this->plugin->work();
135 | $this->assertEquals( 0, $actual );
136 | }
137 |
138 | function test_it_will_return_1_exit_code_if_worker_failed() {
139 | $mock = \Mockery::mock()
140 | ->shouldReceive( 'work' )
141 | ->with()
142 | ->once()
143 | ->andReturn( false )
144 | ->getMock();
145 |
146 | $this->plugin->worker = $mock;
147 |
148 | $actual = $this->plugin->work();
149 | $this->assertEquals( 1, $actual );
150 | }
151 |
152 | function test_it_will_execute_multiple_jobs_on_worker_if_specified() {
153 | $mock = \Mockery::mock()
154 | ->shouldReceive( 'work' )
155 | ->with()
156 | ->times( 10 )
157 | ->andReturn( true )
158 | ->getMock();
159 |
160 | $this->plugin->worker = $mock;
161 |
162 | $this->plugin->config_prefix = 'D';
163 | define( 'D_JOBS_PER_WORKER', 10 );
164 |
165 | $actual = $this->plugin->work();
166 | $this->assertEquals( 0, $actual );
167 | }
168 |
169 | function test_it_will_build_client_and_worker_on_enabled() {
170 | $this->plugin->enable();
171 |
172 | $this->assertInstanceOf(
173 | '\WpMinions\Worker', $this->plugin->worker
174 | );
175 |
176 | $this->assertInstanceOf(
177 | '\WpMinions\Client', $this->plugin->client
178 | );
179 | }
180 |
181 | function test_it_will_not_run_if_already_run() {
182 | $this->plugin->did_run = true;
183 | $actual = $this->plugin->run();
184 | $this->assertFalse( $actual );
185 | }
186 |
187 | function test_it_will_perform_a_job_on_run() {
188 | $mock = \Mockery::mock()
189 | ->shouldReceive( 'work' )
190 | ->with()
191 | ->once()
192 | ->andReturn( true )
193 | ->getMock();
194 |
195 | $this->plugin->worker = $mock;
196 | $actual = $this->plugin->run();
197 |
198 | $this->assertEquals( 0, $actual );
199 | }
200 |
201 | /* helpers */
202 |
203 | }
204 |
--------------------------------------------------------------------------------
/includes/WpMinions/Gearman/Worker.php:
--------------------------------------------------------------------------------
1 | get_gearman_worker();
33 |
34 | if ( $worker !== false ) {
35 | $servers = $this->get_servers();
36 | $group = $this->get_async_group();
37 | $callable = array( $this, 'do_job' );
38 |
39 | try {
40 | if ( empty( $servers ) ) {
41 | $worker->addServer();
42 | } else {
43 | $worker->addServers( implode( ',', $servers ) );
44 | }
45 |
46 | return $worker->addFunction( $group, $callable );
47 | } catch ( \GearmanException $e ) {
48 | $servers = implode( ',', $servers );
49 |
50 | if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
51 | error_log( "Fatal Gearman Error: Failed to register servers ($servers)" );
52 | error_log( " Cause: " . $e->getMessage() );
53 | }
54 |
55 | return false;
56 | }
57 | } else {
58 | return false;
59 | }
60 | }
61 |
62 | /**
63 | * Pulls a job from the Gearman Queue and tries to execute it.
64 | * Errors are logged if the Job failed to execute.
65 | *
66 | * @return bool True if the job could be executed, else false
67 | */
68 | public function work() {
69 | $worker = $this->get_gearman_worker();
70 |
71 | try {
72 | $result = $worker->work();
73 | } catch ( \Exception $e ) {
74 | if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
75 | error_log( 'GearmanWorker->work failed: ' . $e->getMessage() );
76 | }
77 | $result = false;
78 | }
79 |
80 | do_action( 'wp_async_task_after_work', $result, $this );
81 |
82 | return $result;
83 | }
84 |
85 | /* Helpers */
86 | /**
87 | * Executes a Job pulled from Gearman. On a multisite instance
88 | * it switches to the target site before executing the job. And the
89 | * site is restored once executing is finished.
90 | *
91 | * The job data contains,
92 | *
93 | * 1. hook - The name of the target hook to execute
94 | * 2. args - Optional arguments to pass to the target hook
95 | * 3. blog_id - Optional blog on a multisite to switch to, before execution
96 | *
97 | * Actions are fired before and after execution of the target hook.
98 | *
99 | * Eg:- for the action 'foo' The order of execution of actions is,
100 | *
101 | * 1. wp_async_task_before_job
102 | * 2. wp_async_task_before_job_foo
103 | * 3. foo
104 | * 4. wp_async_task_after_job
105 | * 5. wp_async_task_after_job_foo
106 | *
107 | * @param array $job The job object data.
108 | * @return bool True or false based on the status of execution
109 | */
110 | function do_job( $job ) {
111 | $switched = false;
112 |
113 | try {
114 | $job_data = json_decode( $job->workload(), true );
115 | $hook = $job_data['hook'];
116 | $args = $job_data['args'];
117 |
118 | if ( function_exists( 'is_multisite' ) && is_multisite() && $job_data['blog_id'] ) {
119 | $blog_id = $job_data['blog_id'];
120 |
121 | if ( get_current_blog_id() !== $blog_id ) {
122 | switch_to_blog( $blog_id );
123 | $switched = true;
124 | } else {
125 | $switched = false;
126 | }
127 | } else {
128 | $switched = false;
129 | }
130 |
131 | do_action( 'wp_async_task_before_job', $hook, $job );
132 | do_action( 'wp_async_task_before_job_' . $hook, $job );
133 |
134 | do_action( $hook, $args, $job );
135 |
136 | do_action( 'wp_async_task_after_job', $hook, $job );
137 | do_action( 'wp_async_task_after_job_' . $hook, $job );
138 |
139 | $result = true;
140 | } catch ( \Exception $e ) {
141 | error_log(
142 | 'GearmanWorker->do_job failed: ' . $e->getMessage()
143 | );
144 | $result = false;
145 | }
146 |
147 | if ( $switched ) {
148 | restore_current_blog();
149 | }
150 |
151 | return $result;
152 | }
153 |
154 | /**
155 | * The Function Group used to split libGearman functions on a
156 | * multi-network install.
157 | *
158 | * @return string The prefixed group name
159 | */
160 | function get_async_group() {
161 | $key = '';
162 |
163 | if ( defined( 'WP_ASYNC_TASK_SALT' ) ) {
164 | $key .= WP_ASYNC_TASK_SALT . ':';
165 | }
166 |
167 | $key .= 'WP_Async_Task';
168 |
169 | return $key;
170 | }
171 |
172 | /**
173 | * The Gearman Servers to connect to as defined in wp-config.php.
174 | *
175 | * If absent the default server will be used.
176 | *
177 | * @return array The list of servers for this Worker.
178 | */
179 | function get_servers() {
180 | if ( is_null( $this->gearman_servers ) ) {
181 | global $gearman_servers;
182 |
183 | if ( ! empty( $gearman_servers ) ) {
184 | $this->gearman_servers = $gearman_servers;
185 | } else {
186 | $this->gearman_servers = array();
187 | }
188 | }
189 |
190 | return $this->gearman_servers;
191 | }
192 |
193 | /**
194 | * Builds the libGearman Worker Instance if the extension is
195 | * installed. Once created returns the previous instance without
196 | * reinitialization.
197 | *
198 | * @return GearmanWorker|false An instance of GearmanWorker
199 | */
200 | function get_gearman_worker() {
201 | if ( is_null( $this->gearman_worker ) ) {
202 | if ( class_exists( '\GearmanWorker' ) ) {
203 | $this->gearman_worker = new \GearmanWorker();
204 | } else {
205 | $this->gearman_worker = false;
206 | }
207 | }
208 |
209 | return $this->gearman_worker;
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/tests/WpMinions/Gearman/WorkerTest.php:
--------------------------------------------------------------------------------
1 | worker = new Worker();
13 | }
14 |
15 | function tearDown() {
16 | \Mockery::close();
17 | }
18 |
19 | function test_it_knows_if_no_gearman_servers_are_defined() {
20 | $actual = $this->worker->get_servers();
21 | $this->assertEmpty( $actual );
22 | }
23 |
24 | function test_it_knows_if_gearman_servers_are_defined() {
25 | global $gearman_servers;
26 | $gearman_servers = array(
27 | '192.168.1.10:5555',
28 | );
29 |
30 | $actual = $this->worker->get_servers();
31 | $this->assertEquals(
32 | array( '192.168.1.10:5555' ), $actual
33 | );
34 |
35 | unset( $GLOBALS['gearman_servers'] );
36 | }
37 |
38 | function test_it_can_create_a_gearman_worker_if_configured() {
39 | if ( class_exists( '\GearmanWorker' ) ) {
40 | $actual = $this->worker->get_gearman_worker();
41 | $this->assertInstanceOf(
42 | '\GearmanWorker', $actual
43 | );
44 | } else {
45 | //$this->markTestSkipped();
46 | }
47 | }
48 |
49 | function test_it_will_not_register_if_no_valid_gearman_worker() {
50 | $this->worker->gearman_worker = false;
51 | $actual = $this->worker->register();
52 | $this->assertFalse( $actual );
53 | }
54 |
55 | function test_it_will_not_register_if_failed_to_add_servers() {
56 | $this->worker->gearman_worker = \Mockery::mock()
57 | ->shouldReceive( 'addServer' )
58 | ->andThrow( new \GearmanException( 'Failed to set exception option' ) )
59 | ->getMock();
60 |
61 | $actual = $this->worker->register();
62 | $this->assertFalse( $actual );
63 | }
64 |
65 | function test_it_will_add_default_server_to_worker_if_not_defined() {
66 | $mock = \Mockery::mock()
67 | ->shouldReceive( 'addServer' )
68 | ->with()
69 | ->andReturn( true )
70 | ->shouldReceive( 'addFunction' )
71 | ->andReturn( true )
72 | ->getMock();
73 |
74 | $this->worker->gearman_worker = $mock;
75 | $actual = $this->worker->register();
76 | $this->assertTrue( $actual );
77 | }
78 |
79 | function test_it_will_add_multiple_servers_to_worker_if_defined() {
80 | $this->worker->gearman_servers = array(
81 | 'localhost:5554', '127.0.0.1:5555',
82 | );
83 |
84 | $mock = \Mockery::mock()
85 | ->shouldReceive( 'addServers' )
86 | ->with( implode( ',', $this->worker->gearman_servers ) )
87 | ->andReturn( true )
88 | ->shouldReceive( 'addFunction' )
89 | ->andReturn( true )
90 | ->getMock();
91 |
92 | $this->worker->gearman_worker = $mock;
93 | $actual = $this->worker->register();
94 | $this->assertTrue( $actual );
95 | }
96 |
97 | function test_it_will_not_fail_if_the_worker_failed_to_execute() {
98 | $mock = \Mockery::mock()
99 | ->shouldReceive( 'work' )
100 | ->andThrow( new \Exception( 'foo error' ) )
101 | ->getMock();
102 |
103 | $this->worker->gearman_worker = $mock;
104 | $actual = $this->worker->work();
105 |
106 | $this->assertFalse( $actual );
107 | }
108 |
109 | function test_it_will_start_the_gearman_worker_on_work() {
110 | $mock = \Mockery::mock()
111 | ->shouldReceive( 'work' )
112 | ->andReturn( true )
113 | ->getMock();
114 |
115 | $this->worker->gearman_worker = $mock;
116 | $actual = $this->worker->work();
117 |
118 | $this->assertTrue( $actual );
119 | }
120 |
121 | function test_it_can_execute_job_with_specified_arguments() {
122 | $payload = array(
123 | 'hook' => 'action_d',
124 | 'args' => array( 'a' => 1, 'b' => 2 ),
125 | 'blog_id' => false,
126 | );
127 |
128 | $mock = \Mockery::mock()
129 | ->shouldReceive( 'workload' )
130 | ->with()
131 | ->andReturn( json_encode( $payload ) )
132 | ->getMock();
133 |
134 | $action_mock = \Mockery::mock()
135 | ->shouldReceive()
136 | ->andReturn( 'foo' );
137 |
138 | $self = $this;
139 | $args = $payload['args'];
140 |
141 | add_action( 'action_d', array( $this, 'did_action_d' ) );
142 | add_action( 'wp_async_task_before_job', array( $this, 'did_before_job' ) );
143 | add_action( 'wp_async_task_before_job_action_d', array( $this, 'did_before_action_d' ) );
144 | add_action( 'wp_async_task_after_job', array( $this, 'did_after_job' ) );
145 | add_action( 'wp_async_task_after_job_action_d', array( $this, 'did_after_action_d' ) );
146 |
147 | $this->expected_args = $args;
148 | $actual = $this->worker->do_job( $mock );
149 |
150 | $this->assertTrue( $this->ran_action_d );
151 | $this->assertTrue( $this->before_job );
152 | $this->assertTrue( $this->did_before_action_d );
153 | $this->assertTrue( $this->after_job );
154 | $this->assertTrue( $this->did_after_action_d );
155 | }
156 |
157 | function did_action_d( $args ) {
158 | $this->ran_action_d = true;
159 | $this->assertEquals( $this->expected_args, $args );
160 | }
161 |
162 | function did_before_job() {
163 | $this->before_job = true;
164 | }
165 |
166 | function did_after_job() {
167 | $this->after_job = true;
168 | }
169 |
170 | function did_before_action_d() {
171 | $this->did_before_action_d = true;
172 | }
173 |
174 | function did_after_action_d() {
175 | $this->did_after_action_d = true;
176 | }
177 |
178 | function test_it_will_switch_to_target_blog_if_needed() {
179 | if ( ! is_multisite() ) {
180 | return;
181 | }
182 |
183 | $payload = array(
184 | 'hook' => 'action_e',
185 | 'args' => array( 'a' => 1, 'b' => 2 ),
186 | 'blog_id' => 1,
187 | );
188 |
189 | $mock = \Mockery::mock()
190 | ->shouldReceive( 'workload' )
191 | ->with()
192 | ->andReturn( json_encode( $payload ) )
193 | ->getMock();
194 |
195 | $action_mock = \Mockery::mock()
196 | ->shouldReceive()
197 | ->andReturn( 'foo' );
198 |
199 | $self = $this;
200 | $args = $payload['args'];
201 |
202 | add_action( 'action_e', array( $this, 'did_action_e' ) );
203 |
204 | $actual = $this->worker->do_job( $mock );
205 |
206 | $this->assertEquals( 1, $this->actual_site );
207 | }
208 |
209 | function did_action_e( $args ) {
210 | $this->actual_site = get_current_blog_id();
211 | }
212 |
213 | }
214 |
--------------------------------------------------------------------------------
/tests/WpMinions/Gearman/ClientTest.php:
--------------------------------------------------------------------------------
1 | client = new Client();
13 | }
14 |
15 | function tearDown() {
16 | \Mockery::close();
17 | }
18 |
19 | function test_it_knows_if_no_gearman_servers_are_defined() {
20 | $actual = $this->client->get_servers();
21 | $this->assertEmpty( $actual );
22 | }
23 |
24 | function test_it_knows_if_gearman_servers_are_defined() {
25 | global $gearman_servers;
26 | $gearman_servers = array(
27 | '192.168.1.10:5555',
28 | );
29 |
30 | $actual = $this->client->get_servers();
31 | $this->assertEquals(
32 | array( '192.168.1.10:5555' ), $actual
33 | );
34 |
35 | unset( $GLOBALS['gearman_servers'] );
36 | }
37 |
38 | function test_it_can_create_a_gearman_client_if_configured() {
39 | if ( class_exists( '\GearmanClient' ) ) {
40 | $actual = $this->client->get_gearman_client();
41 | $this->assertInstanceOf(
42 | '\GearmanClient', $actual
43 | );
44 | } else {
45 | //$this->markTestSkipped();
46 | }
47 | }
48 |
49 | function test_it_will_not_register_if_no_valid_gearman_client() {
50 | $this->client->gearman_client = \Mockery::mock()
51 | ->shouldReceive( 'addServer' )
52 | ->andThrow( new \GearmanException( 'Failed to set exception option' ) )
53 | ->getMock();
54 |
55 | $actual = $this->client->register();
56 | $this->assertFalse( $actual );
57 | }
58 |
59 | function test_it_will_trap_gearman_error_if_failed_to_register_servers() {
60 | $this->client->gearman_client = false;
61 | $actual = $this->client->register();
62 | $this->assertFalse( $actual );
63 | }
64 |
65 | function test_it_will_add_default_server_to_client_if_not_defined() {
66 | $mock = \Mockery::mock()
67 | ->shouldReceive( 'addServer' )
68 | ->with()
69 | ->andReturn( true )
70 | ->getMock();
71 |
72 | $this->client->gearman_client = $mock;
73 | $actual = $this->client->register();
74 | $this->assertTrue( $actual );
75 | }
76 |
77 | function test_it_will_add_multiple_servers_to_client_if_defined() {
78 | $this->client->gearman_servers = array(
79 | 'localhost:5554', '127.0.0.1:5555',
80 | );
81 |
82 | $mock = \Mockery::mock()
83 | ->shouldReceive( 'addServers' )
84 | ->with( implode( ',', $this->client->gearman_servers ) )
85 | ->andReturn( true )
86 | ->getMock();
87 |
88 | $this->client->gearman_client = $mock;
89 | $actual = $this->client->register();
90 | $this->assertTrue( $actual );
91 | }
92 |
93 | function test_it_has_a_blog_id_if_on_multisite() {
94 | if ( function_exists( 'is_multisite' ) && is_multisite() ) {
95 | $actual = $this->client->get_blog_id();
96 | $this->assertEquals( 1, $actual );
97 | } else {
98 | //$this->markTestSkipped();
99 | }
100 | }
101 |
102 | function test_it_does_not_have_blog_id_on_single_site() {
103 | if ( ! ( function_exists( 'is_multisite' ) && is_multisite() ) ) {
104 | $actual = $this->client->get_blog_id();
105 | $this->assertFalse( $actual );
106 | } else {
107 | //$this->markTestSkipped();
108 | }
109 | }
110 |
111 |
112 | function test_it_uses_blog_id_from_current_site_on_switch() {
113 | //create a new site and switch to it.
114 | if ( function_exists( 'is_multisite' ) && is_multisite() ) {
115 | $blog_id = $this->factory->blog->create();
116 | switch_to_blog( $blog_id );
117 | $actual = $this->client->get_blog_id();
118 | $this->assertEquals( $blog_id, $actual );
119 | restore_current_blog();
120 | }
121 |
122 | }
123 |
124 | function test_it_has_an_async_group() {
125 | if ( defined( 'WP_ASYNC_TASK_SALT' ) ) {
126 | $expected = WP_ASYNC_TASK_SALT . ':WP_Async_Task';
127 | } else {
128 | $expected = 'WP_Async_Task';
129 | }
130 |
131 | $actual = $this->client->get_async_group();
132 | $this->assertEquals( $expected, $actual );
133 | }
134 |
135 | function test_it_knows_when_to_use_high_background_method() {
136 | $actual = $this->client->get_background_method( 'high' );
137 | $this->assertEquals( 'doHighBackground', $actual );
138 | }
139 |
140 | function test_it_knows_when_to_use_low_background_method() {
141 | $actual = $this->client->get_background_method( 'low' );
142 | $this->assertEquals( 'doLowBackground', $actual );
143 | }
144 |
145 | function test_it_knows_when_to_use_normal_background_method() {
146 | $actual = $this->client->get_background_method( 'normal' );
147 | $this->assertEquals( 'doBackground', $actual );
148 | }
149 |
150 | function test_it_will_not_add_hook_to_gearman_if_gearman_is_absent() {
151 | $this->client->gearman_client = false;
152 | $actual = $this->client->add( 'action_a' );
153 | $this->assertFalse( $actual );
154 | }
155 |
156 | function test_it_will_add_hook_to_gearman_client_if_present() {
157 | $payload = array(
158 | 'hook' => 'action_b',
159 | 'args' => array(),
160 | 'blog_id' => function_exists( 'is_multisite' ) && is_multisite() ? get_current_blog_id() : false,
161 | );
162 |
163 | $group = defined( 'WP_ASYNC_TASK_SALT' ) ? WP_ASYNC_TASK_SALT . ':WP_Async_Task' : 'WP_Async_Task';
164 | $mock = \Mockery::mock()
165 | ->shouldReceive('doBackground')
166 | ->with( $group, json_encode( $payload ) )
167 | ->andReturn( true )
168 | ->getMock();
169 |
170 | $this->client->gearman_client = $mock;
171 | $actual = $this->client->add( 'action_b' );
172 | $this->assertTrue( $actual );
173 | }
174 |
175 | function test_it_will_add_hook_to_gearman_client_with_custom_arguments_and_priority() {
176 | $payload = array(
177 | 'hook' => 'action_c',
178 | 'args' => array( 'a' => 1, 'b' => 2 ),
179 | 'blog_id' => is_multisite() ? get_current_blog_id() : false,
180 | );
181 |
182 | $group = defined( 'WP_ASYNC_TASK_SALT' ) ? WP_ASYNC_TASK_SALT . ':WP_Async_Task' : 'WP_Async_Task';
183 | $mock = \Mockery::mock()
184 | ->shouldReceive('doHighBackground')
185 | ->with( $group, json_encode( $payload ) )
186 | ->andReturn( true )
187 | ->getMock();
188 |
189 | $this->client->gearman_client = $mock;
190 | $actual = $this->client->add( 'action_b', $payload, 'high' );
191 | $this->assertTrue( $actual );
192 | }
193 |
194 | }
195 |
--------------------------------------------------------------------------------
/includes/WpMinions/Plugin.php:
--------------------------------------------------------------------------------
1 | did_enable ) {
85 | $this->get_client()->register();
86 | $this->get_worker()->register();
87 |
88 | $this->did_enable = true;
89 | }
90 | }
91 |
92 | /**
93 | * Starts processing jobs in the Worker.
94 | *
95 | * Only one run is permitted.
96 | *
97 | * @return int The exit status code (only for PHPUnit)
98 | */
99 | public function run() {
100 | if ( $this->did_run ) {
101 | return false;
102 | }
103 |
104 | $this->did_run = true;
105 |
106 | return $this->work();
107 | }
108 |
109 | /**
110 | * Executes jobs on the current Worker. A Worker will taken up
111 | * only one job by default. If WP_MINIONS_JOBS_PER_WORKER is defined
112 | * that many jobs will be executed before it exits.
113 | *
114 | * This method will exit with the result code based on
115 | * success/failure of executing the job.
116 | *
117 | * @return int 0 for success and 1 for failure
118 | */
119 | public function work() {
120 | for ( $i = 0; $i < $this->get_jobs_per_worker(); $i++ ) {
121 | $result = $this->get_worker()->work();
122 | $result_code = $result ? 0 : 1;
123 | }
124 |
125 | return $this->quit( $result_code );
126 | }
127 |
128 | /**
129 | * Adds a new job to the Client with the specified arguments and
130 | * priority.
131 | *
132 | * @param string $hook The action hook name for the job
133 | * @param array $args Optional arguments for the job
134 | * @param string $priority Optional priority of the job
135 | * @return bool true or false depending on the Client
136 | */
137 | public function add( $hook, $args = array(), $priority = 'normal' ) {
138 | return $this->get_client()->add(
139 | $hook, $args, $priority
140 | );
141 | }
142 |
143 | /* Helpers */
144 | /**
145 | * Returns the Client object used to add jobs. Creates the instance
146 | * of the client lazily.
147 | *
148 | * @return \WpMinions\Client The client instance
149 | */
150 | function get_client() {
151 | if ( is_null( $this->client ) ) {
152 | $this->client = $this->build_client();
153 | }
154 |
155 | return $this->client;
156 | }
157 |
158 | /**
159 | * Returns the Worker object used to execute jobs. Creates the instance
160 | * of the worker lazily.
161 | *
162 | * @param \WpMinions\Worker The worker instance
163 | */
164 | function get_worker() {
165 | if ( is_null( $this->worker ) ) {
166 | $this->worker = $this->build_worker();
167 | }
168 |
169 | return $this->worker;
170 | }
171 |
172 | /**
173 | * Conditionally builds a new Client object.
174 | *
175 | * If the constant WP_MINIONS_CLIENT_CLASS is defined, it will return an instance of
176 | * that class. If not, WP_MINIONS_BACKEND is checked to chose the client class. If not,
177 | * default to cron client.
178 | *
179 | * @return \WpMinions\Client New instance of the Client
180 | */
181 | function build_client() {
182 | if ( ! $this->has_config( 'CLIENT_CLASS' ) ) {
183 | if ( $this->has_config( 'BACKEND' ) ) {
184 | $backend = $this->get_config( 'BACKEND' );
185 |
186 | if ( 'gearman' === strtolower( $backend ) ) {
187 | return new \WpMinions\Gearman\Client();
188 | } elseif ( 'rabbitmq' === strtolower( $backend ) ) {
189 | return new \WpMinions\RabbitMQ\Client();
190 | } else {
191 | return new \WpMinions\Cron\Client();
192 | }
193 | } else {
194 | return new \WpMinions\Cron\Client();
195 | }
196 | } else {
197 | $klass = $this->get_config( 'CLIENT_CLASS' );
198 | return new $klass();
199 | }
200 | }
201 |
202 | /**
203 | * Conditionally builds a new Worker object.
204 | *
205 | * If the constant WP_MINIONS_WORKER_CLASS is defined it will return an instance of
206 | * that class. If not, WP_MINIONS_BACKEND is checked to chose the worker class. If not,
207 | * default to cron.
208 | *
209 | * @return \WpMinions\Worker New instance of the Worker
210 | */
211 | function build_worker() {
212 | if ( ! $this->has_config( 'WORKER_CLASS' ) ) {
213 | if ( $this->has_config( 'BACKEND' ) ) {
214 | $backend = $this->get_config( 'BACKEND' );
215 |
216 | if ( 'gearman' === strtolower( $backend ) ) {
217 | return new \WpMinions\Gearman\Worker();
218 | } elseif ( 'rabbitmq' === strtolower( $backend ) ) {
219 | return new \WpMinions\RabbitMQ\Worker();
220 | } else {
221 | return new \WpMinions\Cron\Worker();
222 | }
223 | } else {
224 | return new \WpMinions\Cron\Worker();
225 | }
226 | } else {
227 | $klass = $this->get_config( 'WORKER_CLASS' );
228 | return new $klass();
229 | }
230 | }
231 |
232 | /**
233 | * Returns the jobs to execute per worker instance
234 | *
235 | * @return int Defaults to 1
236 | */
237 | function get_jobs_per_worker() {
238 | return $this->get_config(
239 | 'JOBS_PER_WORKER', 1
240 | );
241 | }
242 |
243 | /**
244 | * Helper to pickup config options from Constants with fallbacks.
245 | *
246 | * Order of lookup is,
247 | *
248 | * 1. Local Property
249 | * 2. Constant of that name
250 | * 3. Default specified
251 | *
252 | * Eg:- get_config( 'FOO', 'abc', 'MY' )
253 | *
254 | * will look for,
255 | *
256 | * 1. Local Property $this->my_foo
257 | * 2. Constant MY_FOO
258 | * 3. Defaualt ie:- abc
259 | *
260 | * @param string $constant Name of constant to lookup
261 | * @param string $default Optional default
262 | * @param string $config_prefix Optional config prefix, Default is WP_MINIONS
263 | * @return mixed The value of the config
264 | */
265 | function get_config( $constant, $default = '', $config_prefix = '' ) {
266 | $variable = strtolower( $constant );
267 | $config_prefix = empty( $config_prefix ) ? $this->config_prefix : $config_prefix;
268 | $constant = $config_prefix . '_' . $constant;
269 |
270 | if ( property_exists( $this, $variable ) ) {
271 | if ( is_null( $this->$variable ) ) {
272 | if ( defined( $constant ) ) {
273 | $this->$variable = constant( $constant );
274 | } else {
275 | $this->$variable = $default;
276 | }
277 | }
278 |
279 | return $this->$variable;
280 | } else {
281 | throw new \Exception(
282 | "Fatal Error - Public Var($variable) not declared"
283 | );
284 | }
285 | }
286 |
287 | /**
288 | * Checks if a config option is defined. Empty strings are treated
289 | * as an undefined config option.
290 | *
291 | * @param string $constant The name of the constant
292 | * @return bool True or false depending on whether the config is present
293 | */
294 | function has_config( $constant ) {
295 | $value = $this->get_config( $constant );
296 | return ! empty( $value );
297 | }
298 |
299 | /**
300 | * Helper to quit with a status code. When running under PHPUnit it
301 | * returns the status_code instead of exiting immediately.
302 | *
303 | * @param int $status_code The status between 0-255 to quit with.
304 | */
305 | function quit( $status_code ) {
306 | if ( ! defined( 'PHPUNIT_RUNNER' ) ) {
307 | exit( $status_code );
308 | } else {
309 | return $status_code;
310 | }
311 | }
312 |
313 | /**
314 | * Returns the path to the wp-load.php file.
315 | *
316 | * @return string Path to the wp-load.php file
317 | */
318 | function get_wp_load() {
319 | $wp_dir = dirname( $_SERVER['SCRIPT_FILENAME'] ) ;
320 | return $wp_dir . '/wp-load.php';
321 | }
322 |
323 | /**
324 | * Tries to load WordPress using wp-load.php. If loading fails an
325 | * error message is logged and the Script will exit immediately with
326 | * a status code of 1.
327 | */
328 | function load_wordpress() {
329 | $wp_load = $this->get_wp_load();
330 |
331 | if ( file_exists( $wp_load ) ) {
332 | require_once( $wp_load );
333 | } else {
334 | error_log(
335 | "WP Minions Fatal Error - Cannot find wp-load.php( $wp_load )"
336 | );
337 |
338 | return $this->quit( 1 );
339 | }
340 | }
341 |
342 | }
343 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # WP Minions
2 |
3 | > Provides a framework for using job queues with [WordPress](http://wordpress.org/) for asynchronous task running.
4 | Provides an integration with [Gearman](http://gearman.org/) and [RabbitMQ](https://www.rabbitmq.com) out of the box.
5 |
6 | [](#support-level) [](https://travis-ci.org/10up/WP-Minions) [](https://github.com/10up/WP-Minions/releases/latest) [](https://github.com/10up/WP-Minions/blob/master/LICENSE.md)
7 |
8 | > [!CAUTION]
9 | > As of 12 April 2024, this project is archived and no longer being actively maintained.
10 |
11 | ## Background & Purpose
12 |
13 | As WordPress becomes a more popular publishing platform for increasingly large publishers, with complex workflows, the need for increasingly complex and resource-intensive tasks has only increased. Things like generating reports, expensive API calls, syncing users to mail providers, or even ingesting content from feeds all take a lot of time or a lot of memory (or both), and commonly can't finish within common limitations of web servers, because things like timeouts and memory limits get in the way.
14 |
15 | WP Minions provides a few helper functions that allow you to add tasks to a queue, and specify an action that should be called to trigger the task, just hook a callback into the action using ```add_action()```
16 |
17 | During configuration, a number of minions (workers) are specified. As minions are free, they will take the next task from the queue, call the action, and any callbacks hooked into the action will be run.
18 |
19 | In the situation of needing more ram or higher timeouts, a separate server to process the tasks is ideal - Just set up WordPress on that server like the standard web servers, and up the resources. Make sure not to send any production traffic to the server, and it will exclusively handle tasks from the queue.
20 |
21 | ## Installation
22 |
23 | 1. Install the plugin in WordPress. If desired, you can [download a zip](http://github.com/10up/WP-Minions/archive/master.zip) and install via the WordPress plugin installer.
24 |
25 | 2. Create a symlink at the site root (the same directory as ```wp-settings.php```) that points to the ```wp-minions-runner.php``` file in the plugin (or copy the file, but a symlink will ensure it is updated if the plugin is updated)
26 |
27 | 3. Define a unique salt in `wp-config.php` so that multiple installs don't conflict.
28 | ```php
29 | define( 'WP_ASYNC_TASK_SALT', 'my-unique-salt-1' );
30 | ```
31 |
32 | **Note:** If you are using multisite, you'll also have to add the following to your ```wp-config.php``` file, _after_ the block with the multisite definitions. This is due to the fact that multisite relies on ```HTTP_HOST``` to detect the site/blog it is running under. You'll also want to make sure you are actually defining ```DOMAIN_CURRENT_SITE``` in the multisite configuration.
33 | ```php
34 | if ( ! isset( $_SERVER['HTTP_HOST'] ) && defined( 'DOING_ASYNC' ) && DOING_ASYNC ) {
35 | $_SERVER['HTTP_HOST'] = DOMAIN_CURRENT_SITE;
36 | }
37 | ```
38 |
39 | 4. Next, you'll need to choose your job queue system. Gearman and RabbitMQ are supported out of the box.
40 |
41 | ### Gearman
42 |
43 | There are a few parts to get this all running. First, the Gearman backend needs to be setup - this part will vary depending on your OS. Once that is complete, we can install the WordPress plugin, and set the configuration options for WordPress.
44 |
45 | #### Backend Setup - CentOS 6.x
46 |
47 | 1. You'll need the [EPEL](https://fedoraproject.org/wiki/EPEL) repo for gearman, and the [REMI](http://rpms.famillecollet.com/) repo for some of the php packages. Make sure to enable the appropriate remi repo for the version of php you are using.
48 | - ```wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm && rpm -Uvh epel-release-6*.rpm```
49 | - ```wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm```
50 | - ```rm *.rpm```
51 | 1. Make sure that remi is enabled, as well as any specific version of php you may want in ```/etc/yum.repos.d/remi.repo```
52 | 1. ```yum install gearmand php-pecl-gearman python-pip```
53 | 1. ```easy_install supervisor```
54 | 1. ```chkconfig supervisord on && chkconfig gearmand on```
55 | 1. If everything is running on one server, I would recommend limiting connections to localhost only. If not, you'll want to set up firewall rules to only allow certain clients to connect on the Gearman port (Default 4730)
56 | - edit ```/etc/sysconfig/gearmand``` - set ```OPTIONS="--listen=localhost"```
57 | 1. ```service gearmand start```
58 |
59 | #### Backend Setup - CentOS 7.x
60 |
61 | 1. You'll need the [EPEL](https://fedoraproject.org/wiki/EPEL) repo for gearman, and the [REMI](http://rpms.famillecollet.com/) repo for some of the php packages.
62 | - ```yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm```
63 | - ```yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm```
64 | 1. ```yum install gearmand php-pecl-gearman --enablerepo=remi-php```. For example, if you are using php 7.2 your command would look like this ```yum install gearmand php-pecl-gearman --enablerepo=remi-php72```
65 | 1. Optionally, install supervisord if you prefer it
66 | - ```yum install python-pip```
67 | - ```easy_install supervisor```
68 | 1. If everything is running on one server, I would recommend limiting connections to localhost only. If not, you'll want to set up firewall rules to only allow certain clients to connect on the Gearman port (Default 4730)
69 | - edit ```/etc/sysconfig/gearmand``` - set ```OPTIONS="--listen=localhost"```
70 | 1. ```systemctl enable gearmand```
71 | 1. ```systemctl start gearmand```
72 |
73 | #### Backend Setup - Ubuntu
74 |
75 | As you go through this, you may need to install additional packages, if you do not have them already, such as php-pear or a php*-dev package
76 |
77 | 1. ```apt-get update```
78 | 1. ```apt-get install gearman python-pip libgearman-dev supervisor```
79 | 1. ```pecl install gearman```
80 | 1. Once pecl install is complete, it will tell you to place something like ```extension=gearman.so``` into your php.ini file - Do this.
81 | 1. ```update-rc.d gearman-job-server defaults && update-rc.d supervisor defaults```
82 | 1. If everything is running on one server, I would recommend limiting connections to localhost only. If not, you'll want to set up firewall rules to only allow certain clients to connect on the Gearman port (Default 4730)
83 | - edit ```/etc/default/gearman-job-server``` - set ```PARAMS="--listen=localhost"```
84 | 1. ```service gearman-job-server restart```
85 |
86 | #### Supervisor Configuration
87 |
88 | Filling in values in `````` as required, add the following config to either ```/etc/supervisord.conf``` (CentOS) or ```/etc/supervisor/supervisord.conf``` (Ubuntu)
89 |
90 | ```sh
91 | [program:my_wp_minions_workers]
92 | command=/usr/bin/env php /wp-minions-runner.php
93 | process_name=%(program_name)s-%(process_num)02d
94 | numprocs=
95 | directory=
96 | autostart=true
97 | autorestart=true
98 | killasgroup=true
99 | user=
100 | ```
101 |
102 | * path_to_wordpress: Absolute path to the root of your WordPress install, ex: ```/var/www/html/wordpress```
103 | * number_of_minions: How many minions should be spawned (How many jobs can be running at once).
104 | * path_to_temp_directory: probably should just be the same as path_to_wordpress.
105 | * user: The system user to run the processes under, probably apache (CentOS), nginx (CentOS), or www-data (Ubuntu).
106 | * You can optionally change the "my_wp_minions_workers" text to something more descriptive, if you'd like.
107 |
108 | After updating the supervisor configuration, restart the service (CentOS or Ubuntu)
109 |
110 | ```
111 | systemctl restart supervisord
112 | ```
113 | ```
114 | service supervisor restart
115 | ```
116 |
117 | #### Systemd Configuration (CentOS 7.x)
118 |
119 | Filling in values in `````` as required, add the following to /etc/systemd/system/wp-minions-runner@.service
120 |
121 | ```
122 | [Unit]
123 | Description=WP-Minions Runner %i
124 | After=network.target
125 |
126 | [Service]
127 | PIDFile=/var/run/wp-minions-runner.%i.pid
128 | User=
129 | Type=simple
130 | ExecStart=/usr/bin/env php /wp-minions-runner.php
131 | Restart=always
132 |
133 | [Install]
134 | WantedBy=multi-user.target
135 | ```
136 | * path_to_wordpress: Absolute path to the root of your WordPress install, ex: ```/var/www/html/wordpress```
137 | * user: The system user to run the processes under, probably apache (CentOS), nginx (CentOS), or www-data (Ubuntu).
138 |
139 | Reload systemd:
140 |
141 | ```systemctl daemon-reload```
142 |
143 | Enable and start as many runners as you'd like to have running:
144 |
145 | ```
146 | systemctl enable wp-minions-runner@{1..n}
147 | systemctl start wp-minions-runner@{1..n}
148 | ```
149 |
150 | Where 'n' is the number of processes you want.
151 |
152 | #### WordPress Configuration
153 |
154 | Define the `WP_MINIONS_BACKEND` constant in your ```wp-config.php```. Valid values are `gearman` or `rabbitmq`. If left blank, it will default to a cron client.
155 | ```
156 | define( 'WP_MINIONS_BACKEND', 'gearman' );
157 | ```
158 |
159 | If your job queue service not running locally or uses a non-standard port, you'll need define your servers in ```wp-config.php```
160 |
161 | ```:php
162 | # Gearman config
163 | global $gearman_servers;
164 | $gearman_servers = array(
165 | '127.0.0.1:4730',
166 | );
167 | ```
168 |
169 | ```:php
170 | # RabbitMQ config
171 | global $rabbitmq_server;
172 | $rabbitmq_server = array(
173 | 'host' => '127.0.0.1',
174 | 'port' => 5672,
175 | 'username' => 'guest',
176 | 'password' => 'guest',
177 | );
178 |
179 | Note: On RabbitMQ the guest/guest account is the default administrator account, RabbitMQ will only allow connections connections on that account from localhost. Connections to any non-loopback address will be denied. See the RabbitMQ manual on [user management](https://www.rabbitmq.com/rabbitmqctl.8.html#User_Management) and [Access Control](https://www.rabbitmq.com/rabbitmqctl.8.html#Access_Control) for information on adding users and allowing them access to RabbitMQ resources.
180 |
181 | ## MySQL Persistent Queue (Recommended)
182 |
183 | By default, gearman will store the job queue in memory. If for whatever reason the gearman service goes away, so does the queue. For persistence, you can optionally use a MySQL database for the job queue:
184 |
185 | #### CentOS
186 |
187 | Edit the gearman config at ```/etc/sysconfig/gearmand```, adding the following to the OPTIONS line (or creating the line, if it doesn't exist yet), inserting database credentials as necessary:
188 | ```sh
189 | OPTIONS="-q MySQL --mysql-host=localhost --mysql-port=3306 --mysql-user= --mysql-password= --mysql-db=gearman --mysql-table=gearman_queue"
190 | ```
191 |
192 | #### Ubuntu
193 |
194 | Edit the gearman config at ```/etc/default/gearman-job-server```, adding the following to the PARAMS line (or creating the line, if it doesn't exist yet), inserting database credentials as necessary:
195 | ```sh
196 | PARAMS="-q MySQL --mysql-host=localhost --mysql-port=3306 --mysql-user= --mysql-password= --mysql-db=gearman --mysql-table=gearman_queue"
197 | ```
198 |
199 | Note: For some setups, the above will not work as ```/etc/default/gearman-job-server``` does not get read. If you don't see the persistent queue setup then:
200 |
201 | 1. Create a `gearman` db in mysql (the database must be present in the database, but when gearmand is initialized the first time it will create the table).
202 | 2. Create a file in `/etc/gearmand.conf`
203 | 3. In the file paste the configuration all on one line:
204 |
205 | ```sh
206 | -q MySQL --mysql-host=localhost --mysql-port=3306 --mysql-user= --mysql-password= --mysql-db=gearman --mysql-table=gearman_queue
207 | ```
208 |
209 | Then restart the gearman-job-server: ```sudo service gearman-job-server restart```.
210 |
211 |
212 | ## Verification
213 |
214 | Once everything is installed, you can quickly make sure your job queue is accepting jobs with the ```test-client.php``` and ```test-worker.php``` files located in the `system-tests/YOURQUEUE` directory. The worker is configured to reverse any text passed to it. In the client file, we pass "Hello World" to the worker.
215 |
216 | In one window, run ```php test-worker.php``` - You'll now have one worker process running, waiting for jobs.
217 |
218 | In another window, run ```php test-client.php "Hello World"``` - You should see "dlroW olleH" printed on your screen.
219 |
220 | ```ctrl-c``` will stop the worker once you are done testing.
221 |
222 | ## Usage
223 |
224 | Once configured and activated, you'll have access to ```wp_async_task_add()```. If you are at all familiar with ```wp_schedule_single_event()```, the way ```wp_async_task_add()``` works should be very familiar to you.
225 |
226 | The function takes up to three arguments, the first of which is required:
227 |
228 | 1. ```$hook```: This is the name of the action hook to execute when the job runs. Your callback function should hook into this with ```add_action( $hook, $callback )```
229 | 1. ```$args```: This is optional, and defaults to an empty array. You can pass an array of arbitrary data to this, and it will be passed to your callback function.
230 | 1. ```$priority```: This is optional, and defaults to "normal". Other valid options are "high" or "low". High priority jobs will be run before normal priority jobs, even if they normal priority job has been in the queue longer.
231 |
232 | Set an option in the database, when a worker becomes available:
233 |
234 | ```php
235 | // Add a task, that will call the "myplugin_update_option" action when it is run
236 | wp_async_task_add( 'myplugin_update_option', array( 'mykey' => 'myvalue' ) );
237 |
238 | function myplugin_update_option_callback( $args ) {
239 | // In reality, you are probably doing a lot of resource intensive work here
240 | update_option( 'my-option-name', $args['mykey'] );
241 | }
242 |
243 | // Add the action that links the task and the callback.
244 | // Notice the hook below is the same as the hook provided to wp_async_task_add.
245 | add_action( 'myplugin_update_option', 'myplugin_update_option_callback' );
246 |
247 | ```
248 | Once a worker is free, and runs the above task, you'd have an option called "my-option-name" in the options table, with a value of "myvalue", since "myvalue" was passed in via the ```$args```
249 |
250 | ## Customization
251 |
252 | The following constants can be used to customize the behaviour of WP Minions.
253 |
254 | 1. `WP_MINIONS_JOBS_PER_WORKER` - The number of jobs to execute per Worker,
255 | default is 1. Running multiple jobs per worker will reduce the number
256 | workers spawned, and can significantly boost performance. However too
257 | large a value will cause issues if you have memory leaks. Use with
258 | caution.
259 |
260 | 2. `WP_MINIONS_CLIENT_CLASS` - You can also alter the Client class used to
261 | send jobs to your job queue. It should match the interface of
262 | `\WpMinions\Client`.
263 |
264 | 3. `WP_MINIONS_WORKER_CLASS` - Similarly you can alter the Worker class used
265 | to execute jobs. It should match the interface of `\WpMinions\Worker`.
266 |
267 | ## Issues
268 |
269 | If you identify any errors or have an idea for improving the plugin, please [open an issue](https://github.com/10up/WP-Minions/issues). We're excited to see what the community thinks of this project, and we would love your input!
270 |
271 | ## Support Level
272 |
273 | **Archived:** This project is no longer maintained by 10up. We are no longer responding to Issues or Pull Requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!
274 |
275 | ## Like what you see?
276 |
277 |
278 |
279 |
280 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "579b825ca4a8572eec781af18d9ab14c",
8 | "packages": [
9 | {
10 | "name": "composer/installers",
11 | "version": "v1.6.0",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/composer/installers.git",
15 | "reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/composer/installers/zipball/cfcca6b1b60bc4974324efb5783c13dca6932b5b",
20 | "reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "composer-plugin-api": "^1.0"
25 | },
26 | "replace": {
27 | "roundcube/plugin-installer": "*",
28 | "shama/baton": "*"
29 | },
30 | "require-dev": {
31 | "composer/composer": "1.0.*@dev",
32 | "phpunit/phpunit": "^4.8.36"
33 | },
34 | "type": "composer-plugin",
35 | "extra": {
36 | "class": "Composer\\Installers\\Plugin",
37 | "branch-alias": {
38 | "dev-master": "1.0-dev"
39 | }
40 | },
41 | "autoload": {
42 | "psr-4": {
43 | "Composer\\Installers\\": "src/Composer/Installers"
44 | }
45 | },
46 | "notification-url": "https://packagist.org/downloads/",
47 | "license": [
48 | "MIT"
49 | ],
50 | "authors": [
51 | {
52 | "name": "Kyle Robinson Young",
53 | "email": "kyle@dontkry.com",
54 | "homepage": "https://github.com/shama"
55 | }
56 | ],
57 | "description": "A multi-framework Composer library installer",
58 | "homepage": "https://composer.github.io/installers/",
59 | "keywords": [
60 | "Craft",
61 | "Dolibarr",
62 | "Eliasis",
63 | "Hurad",
64 | "ImageCMS",
65 | "Kanboard",
66 | "Lan Management System",
67 | "MODX Evo",
68 | "Mautic",
69 | "Maya",
70 | "OXID",
71 | "Plentymarkets",
72 | "Porto",
73 | "RadPHP",
74 | "SMF",
75 | "Thelia",
76 | "WolfCMS",
77 | "agl",
78 | "aimeos",
79 | "annotatecms",
80 | "attogram",
81 | "bitrix",
82 | "cakephp",
83 | "chef",
84 | "cockpit",
85 | "codeigniter",
86 | "concrete5",
87 | "croogo",
88 | "dokuwiki",
89 | "drupal",
90 | "eZ Platform",
91 | "elgg",
92 | "expressionengine",
93 | "fuelphp",
94 | "grav",
95 | "installer",
96 | "itop",
97 | "joomla",
98 | "kohana",
99 | "laravel",
100 | "lavalite",
101 | "lithium",
102 | "magento",
103 | "majima",
104 | "mako",
105 | "mediawiki",
106 | "modulework",
107 | "modx",
108 | "moodle",
109 | "osclass",
110 | "phpbb",
111 | "piwik",
112 | "ppi",
113 | "puppet",
114 | "pxcms",
115 | "reindex",
116 | "roundcube",
117 | "shopware",
118 | "silverstripe",
119 | "sydes",
120 | "symfony",
121 | "typo3",
122 | "wordpress",
123 | "yawik",
124 | "zend",
125 | "zikula"
126 | ],
127 | "time": "2018-08-27T06:10:37+00:00"
128 | },
129 | {
130 | "name": "php-amqplib/php-amqplib",
131 | "version": "v2.8.0",
132 | "source": {
133 | "type": "git",
134 | "url": "https://github.com/php-amqplib/php-amqplib.git",
135 | "reference": "7df8553bd8b347cf6e919dd4a21e75f371547aa0"
136 | },
137 | "dist": {
138 | "type": "zip",
139 | "url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/7df8553bd8b347cf6e919dd4a21e75f371547aa0",
140 | "reference": "7df8553bd8b347cf6e919dd4a21e75f371547aa0",
141 | "shasum": ""
142 | },
143 | "require": {
144 | "ext-bcmath": "*",
145 | "php": ">=5.4.0"
146 | },
147 | "replace": {
148 | "videlalvaro/php-amqplib": "self.version"
149 | },
150 | "require-dev": {
151 | "phpdocumentor/phpdocumentor": "^2.9",
152 | "phpunit/phpunit": "^4.8",
153 | "scrutinizer/ocular": "^1.1",
154 | "squizlabs/php_codesniffer": "^2.5"
155 | },
156 | "suggest": {
157 | "ext-sockets": "Use AMQPSocketConnection"
158 | },
159 | "type": "library",
160 | "extra": {
161 | "branch-alias": {
162 | "dev-master": "2.8-dev"
163 | }
164 | },
165 | "autoload": {
166 | "psr-4": {
167 | "PhpAmqpLib\\": "PhpAmqpLib/"
168 | }
169 | },
170 | "notification-url": "https://packagist.org/downloads/",
171 | "license": [
172 | "LGPL-2.1-or-later"
173 | ],
174 | "authors": [
175 | {
176 | "name": "Alvaro Videla",
177 | "role": "Original Maintainer"
178 | },
179 | {
180 | "name": "John Kelly",
181 | "email": "johnmkelly86@gmail.com",
182 | "role": "Maintainer"
183 | },
184 | {
185 | "name": "Raúl Araya",
186 | "email": "nubeiro@gmail.com",
187 | "role": "Maintainer"
188 | }
189 | ],
190 | "description": "Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.",
191 | "homepage": "https://github.com/php-amqplib/php-amqplib/",
192 | "keywords": [
193 | "message",
194 | "queue",
195 | "rabbitmq"
196 | ],
197 | "time": "2018-10-23T18:48:24+00:00"
198 | }
199 | ],
200 | "packages-dev": [
201 | {
202 | "name": "hamcrest/hamcrest-php",
203 | "version": "v1.2.2",
204 | "source": {
205 | "type": "git",
206 | "url": "https://github.com/hamcrest/hamcrest-php.git",
207 | "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c"
208 | },
209 | "dist": {
210 | "type": "zip",
211 | "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/b37020aa976fa52d3de9aa904aa2522dc518f79c",
212 | "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c",
213 | "shasum": ""
214 | },
215 | "require": {
216 | "php": ">=5.3.2"
217 | },
218 | "replace": {
219 | "cordoval/hamcrest-php": "*",
220 | "davedevelopment/hamcrest-php": "*",
221 | "kodova/hamcrest-php": "*"
222 | },
223 | "require-dev": {
224 | "phpunit/php-file-iterator": "1.3.3",
225 | "satooshi/php-coveralls": "dev-master"
226 | },
227 | "type": "library",
228 | "autoload": {
229 | "classmap": [
230 | "hamcrest"
231 | ],
232 | "files": [
233 | "hamcrest/Hamcrest.php"
234 | ]
235 | },
236 | "notification-url": "https://packagist.org/downloads/",
237 | "license": [
238 | "BSD"
239 | ],
240 | "description": "This is the PHP port of Hamcrest Matchers",
241 | "keywords": [
242 | "test"
243 | ],
244 | "time": "2015-05-11T14:41:42+00:00"
245 | },
246 | {
247 | "name": "mockery/mockery",
248 | "version": "0.9.9",
249 | "source": {
250 | "type": "git",
251 | "url": "https://github.com/mockery/mockery.git",
252 | "reference": "6fdb61243844dc924071d3404bb23994ea0b6856"
253 | },
254 | "dist": {
255 | "type": "zip",
256 | "url": "https://api.github.com/repos/mockery/mockery/zipball/6fdb61243844dc924071d3404bb23994ea0b6856",
257 | "reference": "6fdb61243844dc924071d3404bb23994ea0b6856",
258 | "shasum": ""
259 | },
260 | "require": {
261 | "hamcrest/hamcrest-php": "~1.1",
262 | "lib-pcre": ">=7.0",
263 | "php": ">=5.3.2"
264 | },
265 | "require-dev": {
266 | "phpunit/phpunit": "~4.0"
267 | },
268 | "type": "library",
269 | "extra": {
270 | "branch-alias": {
271 | "dev-master": "0.9.x-dev"
272 | }
273 | },
274 | "autoload": {
275 | "psr-0": {
276 | "Mockery": "library/"
277 | }
278 | },
279 | "notification-url": "https://packagist.org/downloads/",
280 | "license": [
281 | "BSD-3-Clause"
282 | ],
283 | "authors": [
284 | {
285 | "name": "Pádraic Brady",
286 | "email": "padraic.brady@gmail.com",
287 | "homepage": "http://blog.astrumfutura.com"
288 | },
289 | {
290 | "name": "Dave Marshall",
291 | "email": "dave.marshall@atstsolutions.co.uk",
292 | "homepage": "http://davedevelopment.co.uk"
293 | }
294 | ],
295 | "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.",
296 | "homepage": "http://github.com/padraic/mockery",
297 | "keywords": [
298 | "BDD",
299 | "TDD",
300 | "library",
301 | "mock",
302 | "mock objects",
303 | "mockery",
304 | "stub",
305 | "test",
306 | "test double",
307 | "testing"
308 | ],
309 | "time": "2017-02-28T12:52:32+00:00"
310 | },
311 | {
312 | "name": "phpunit/php-code-coverage",
313 | "version": "1.2.18",
314 | "source": {
315 | "type": "git",
316 | "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
317 | "reference": "fe2466802556d3fe4e4d1d58ffd3ccfd0a19be0b"
318 | },
319 | "dist": {
320 | "type": "zip",
321 | "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/fe2466802556d3fe4e4d1d58ffd3ccfd0a19be0b",
322 | "reference": "fe2466802556d3fe4e4d1d58ffd3ccfd0a19be0b",
323 | "shasum": ""
324 | },
325 | "require": {
326 | "php": ">=5.3.3",
327 | "phpunit/php-file-iterator": ">=1.3.0@stable",
328 | "phpunit/php-text-template": ">=1.2.0@stable",
329 | "phpunit/php-token-stream": ">=1.1.3,<1.3.0"
330 | },
331 | "require-dev": {
332 | "phpunit/phpunit": "3.7.*@dev"
333 | },
334 | "suggest": {
335 | "ext-dom": "*",
336 | "ext-xdebug": ">=2.0.5"
337 | },
338 | "type": "library",
339 | "extra": {
340 | "branch-alias": {
341 | "dev-master": "1.2.x-dev"
342 | }
343 | },
344 | "autoload": {
345 | "classmap": [
346 | "PHP/"
347 | ]
348 | },
349 | "notification-url": "https://packagist.org/downloads/",
350 | "include-path": [
351 | ""
352 | ],
353 | "license": [
354 | "BSD-3-Clause"
355 | ],
356 | "authors": [
357 | {
358 | "name": "Sebastian Bergmann",
359 | "email": "sb@sebastian-bergmann.de",
360 | "role": "lead"
361 | }
362 | ],
363 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
364 | "homepage": "https://github.com/sebastianbergmann/php-code-coverage",
365 | "keywords": [
366 | "coverage",
367 | "testing",
368 | "xunit"
369 | ],
370 | "time": "2014-09-02T10:13:14+00:00"
371 | },
372 | {
373 | "name": "phpunit/php-file-iterator",
374 | "version": "1.4.5",
375 | "source": {
376 | "type": "git",
377 | "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
378 | "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4"
379 | },
380 | "dist": {
381 | "type": "zip",
382 | "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4",
383 | "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4",
384 | "shasum": ""
385 | },
386 | "require": {
387 | "php": ">=5.3.3"
388 | },
389 | "type": "library",
390 | "extra": {
391 | "branch-alias": {
392 | "dev-master": "1.4.x-dev"
393 | }
394 | },
395 | "autoload": {
396 | "classmap": [
397 | "src/"
398 | ]
399 | },
400 | "notification-url": "https://packagist.org/downloads/",
401 | "license": [
402 | "BSD-3-Clause"
403 | ],
404 | "authors": [
405 | {
406 | "name": "Sebastian Bergmann",
407 | "email": "sb@sebastian-bergmann.de",
408 | "role": "lead"
409 | }
410 | ],
411 | "description": "FilterIterator implementation that filters files based on a list of suffixes.",
412 | "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
413 | "keywords": [
414 | "filesystem",
415 | "iterator"
416 | ],
417 | "time": "2017-11-27T13:52:08+00:00"
418 | },
419 | {
420 | "name": "phpunit/php-text-template",
421 | "version": "1.2.1",
422 | "source": {
423 | "type": "git",
424 | "url": "https://github.com/sebastianbergmann/php-text-template.git",
425 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
426 | },
427 | "dist": {
428 | "type": "zip",
429 | "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
430 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
431 | "shasum": ""
432 | },
433 | "require": {
434 | "php": ">=5.3.3"
435 | },
436 | "type": "library",
437 | "autoload": {
438 | "classmap": [
439 | "src/"
440 | ]
441 | },
442 | "notification-url": "https://packagist.org/downloads/",
443 | "license": [
444 | "BSD-3-Clause"
445 | ],
446 | "authors": [
447 | {
448 | "name": "Sebastian Bergmann",
449 | "email": "sebastian@phpunit.de",
450 | "role": "lead"
451 | }
452 | ],
453 | "description": "Simple template engine.",
454 | "homepage": "https://github.com/sebastianbergmann/php-text-template/",
455 | "keywords": [
456 | "template"
457 | ],
458 | "time": "2015-06-21T13:50:34+00:00"
459 | },
460 | {
461 | "name": "phpunit/php-timer",
462 | "version": "1.0.9",
463 | "source": {
464 | "type": "git",
465 | "url": "https://github.com/sebastianbergmann/php-timer.git",
466 | "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f"
467 | },
468 | "dist": {
469 | "type": "zip",
470 | "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f",
471 | "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f",
472 | "shasum": ""
473 | },
474 | "require": {
475 | "php": "^5.3.3 || ^7.0"
476 | },
477 | "require-dev": {
478 | "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
479 | },
480 | "type": "library",
481 | "extra": {
482 | "branch-alias": {
483 | "dev-master": "1.0-dev"
484 | }
485 | },
486 | "autoload": {
487 | "classmap": [
488 | "src/"
489 | ]
490 | },
491 | "notification-url": "https://packagist.org/downloads/",
492 | "license": [
493 | "BSD-3-Clause"
494 | ],
495 | "authors": [
496 | {
497 | "name": "Sebastian Bergmann",
498 | "email": "sb@sebastian-bergmann.de",
499 | "role": "lead"
500 | }
501 | ],
502 | "description": "Utility class for timing",
503 | "homepage": "https://github.com/sebastianbergmann/php-timer/",
504 | "keywords": [
505 | "timer"
506 | ],
507 | "time": "2017-02-26T11:10:40+00:00"
508 | },
509 | {
510 | "name": "phpunit/php-token-stream",
511 | "version": "1.2.2",
512 | "source": {
513 | "type": "git",
514 | "url": "https://github.com/sebastianbergmann/php-token-stream.git",
515 | "reference": "ad4e1e23ae01b483c16f600ff1bebec184588e32"
516 | },
517 | "dist": {
518 | "type": "zip",
519 | "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/ad4e1e23ae01b483c16f600ff1bebec184588e32",
520 | "reference": "ad4e1e23ae01b483c16f600ff1bebec184588e32",
521 | "shasum": ""
522 | },
523 | "require": {
524 | "ext-tokenizer": "*",
525 | "php": ">=5.3.3"
526 | },
527 | "type": "library",
528 | "extra": {
529 | "branch-alias": {
530 | "dev-master": "1.2-dev"
531 | }
532 | },
533 | "autoload": {
534 | "classmap": [
535 | "PHP/"
536 | ]
537 | },
538 | "notification-url": "https://packagist.org/downloads/",
539 | "include-path": [
540 | ""
541 | ],
542 | "license": [
543 | "BSD-3-Clause"
544 | ],
545 | "authors": [
546 | {
547 | "name": "Sebastian Bergmann",
548 | "email": "sb@sebastian-bergmann.de",
549 | "role": "lead"
550 | }
551 | ],
552 | "description": "Wrapper around PHP's tokenizer extension.",
553 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/",
554 | "keywords": [
555 | "tokenizer"
556 | ],
557 | "time": "2014-03-03T05:10:30+00:00"
558 | },
559 | {
560 | "name": "phpunit/phpunit",
561 | "version": "3.7.38",
562 | "source": {
563 | "type": "git",
564 | "url": "https://github.com/sebastianbergmann/phpunit.git",
565 | "reference": "38709dc22d519a3d1be46849868aa2ddf822bcf6"
566 | },
567 | "dist": {
568 | "type": "zip",
569 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/38709dc22d519a3d1be46849868aa2ddf822bcf6",
570 | "reference": "38709dc22d519a3d1be46849868aa2ddf822bcf6",
571 | "shasum": ""
572 | },
573 | "require": {
574 | "ext-ctype": "*",
575 | "ext-dom": "*",
576 | "ext-json": "*",
577 | "ext-pcre": "*",
578 | "ext-reflection": "*",
579 | "ext-spl": "*",
580 | "php": ">=5.3.3",
581 | "phpunit/php-code-coverage": "~1.2",
582 | "phpunit/php-file-iterator": "~1.3",
583 | "phpunit/php-text-template": "~1.1",
584 | "phpunit/php-timer": "~1.0",
585 | "phpunit/phpunit-mock-objects": "~1.2",
586 | "symfony/yaml": "~2.0"
587 | },
588 | "require-dev": {
589 | "pear-pear.php.net/pear": "1.9.4"
590 | },
591 | "suggest": {
592 | "phpunit/php-invoker": "~1.1"
593 | },
594 | "bin": [
595 | "composer/bin/phpunit"
596 | ],
597 | "type": "library",
598 | "extra": {
599 | "branch-alias": {
600 | "dev-master": "3.7.x-dev"
601 | }
602 | },
603 | "autoload": {
604 | "classmap": [
605 | "PHPUnit/"
606 | ]
607 | },
608 | "notification-url": "https://packagist.org/downloads/",
609 | "include-path": [
610 | "",
611 | "../../symfony/yaml/"
612 | ],
613 | "license": [
614 | "BSD-3-Clause"
615 | ],
616 | "authors": [
617 | {
618 | "name": "Sebastian Bergmann",
619 | "email": "sebastian@phpunit.de",
620 | "role": "lead"
621 | }
622 | ],
623 | "description": "The PHP Unit Testing framework.",
624 | "homepage": "http://www.phpunit.de/",
625 | "keywords": [
626 | "phpunit",
627 | "testing",
628 | "xunit"
629 | ],
630 | "time": "2014-10-17T09:04:17+00:00"
631 | },
632 | {
633 | "name": "phpunit/phpunit-mock-objects",
634 | "version": "1.2.3",
635 | "source": {
636 | "type": "git",
637 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
638 | "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875"
639 | },
640 | "dist": {
641 | "type": "zip",
642 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5794e3c5c5ba0fb037b11d8151add2a07fa82875",
643 | "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875",
644 | "shasum": ""
645 | },
646 | "require": {
647 | "php": ">=5.3.3",
648 | "phpunit/php-text-template": ">=1.1.1@stable"
649 | },
650 | "suggest": {
651 | "ext-soap": "*"
652 | },
653 | "type": "library",
654 | "autoload": {
655 | "classmap": [
656 | "PHPUnit/"
657 | ]
658 | },
659 | "notification-url": "https://packagist.org/downloads/",
660 | "include-path": [
661 | ""
662 | ],
663 | "license": [
664 | "BSD-3-Clause"
665 | ],
666 | "authors": [
667 | {
668 | "name": "Sebastian Bergmann",
669 | "email": "sb@sebastian-bergmann.de",
670 | "role": "lead"
671 | }
672 | ],
673 | "description": "Mock Object library for PHPUnit",
674 | "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
675 | "keywords": [
676 | "mock",
677 | "xunit"
678 | ],
679 | "time": "2013-01-13T10:24:48+00:00"
680 | },
681 | {
682 | "name": "symfony/polyfill-ctype",
683 | "version": "v1.10.0",
684 | "source": {
685 | "type": "git",
686 | "url": "https://github.com/symfony/polyfill-ctype.git",
687 | "reference": "e3d826245268269cd66f8326bd8bc066687b4a19"
688 | },
689 | "dist": {
690 | "type": "zip",
691 | "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19",
692 | "reference": "e3d826245268269cd66f8326bd8bc066687b4a19",
693 | "shasum": ""
694 | },
695 | "require": {
696 | "php": ">=5.3.3"
697 | },
698 | "suggest": {
699 | "ext-ctype": "For best performance"
700 | },
701 | "type": "library",
702 | "extra": {
703 | "branch-alias": {
704 | "dev-master": "1.9-dev"
705 | }
706 | },
707 | "autoload": {
708 | "psr-4": {
709 | "Symfony\\Polyfill\\Ctype\\": ""
710 | },
711 | "files": [
712 | "bootstrap.php"
713 | ]
714 | },
715 | "notification-url": "https://packagist.org/downloads/",
716 | "license": [
717 | "MIT"
718 | ],
719 | "authors": [
720 | {
721 | "name": "Symfony Community",
722 | "homepage": "https://symfony.com/contributors"
723 | },
724 | {
725 | "name": "Gert de Pagter",
726 | "email": "BackEndTea@gmail.com"
727 | }
728 | ],
729 | "description": "Symfony polyfill for ctype functions",
730 | "homepage": "https://symfony.com",
731 | "keywords": [
732 | "compatibility",
733 | "ctype",
734 | "polyfill",
735 | "portable"
736 | ],
737 | "time": "2018-08-06T14:22:27+00:00"
738 | },
739 | {
740 | "name": "symfony/yaml",
741 | "version": "v2.8.47",
742 | "source": {
743 | "type": "git",
744 | "url": "https://github.com/symfony/yaml.git",
745 | "reference": "0e16589861f192dbffb19b06683ce3ef58f7f99d"
746 | },
747 | "dist": {
748 | "type": "zip",
749 | "url": "https://api.github.com/repos/symfony/yaml/zipball/0e16589861f192dbffb19b06683ce3ef58f7f99d",
750 | "reference": "0e16589861f192dbffb19b06683ce3ef58f7f99d",
751 | "shasum": ""
752 | },
753 | "require": {
754 | "php": ">=5.3.9",
755 | "symfony/polyfill-ctype": "~1.8"
756 | },
757 | "type": "library",
758 | "extra": {
759 | "branch-alias": {
760 | "dev-master": "2.8-dev"
761 | }
762 | },
763 | "autoload": {
764 | "psr-4": {
765 | "Symfony\\Component\\Yaml\\": ""
766 | },
767 | "exclude-from-classmap": [
768 | "/Tests/"
769 | ]
770 | },
771 | "notification-url": "https://packagist.org/downloads/",
772 | "license": [
773 | "MIT"
774 | ],
775 | "authors": [
776 | {
777 | "name": "Fabien Potencier",
778 | "email": "fabien@symfony.com"
779 | },
780 | {
781 | "name": "Symfony Community",
782 | "homepage": "https://symfony.com/contributors"
783 | }
784 | ],
785 | "description": "Symfony Yaml Component",
786 | "homepage": "https://symfony.com",
787 | "time": "2018-10-02T16:27:16+00:00"
788 | }
789 | ],
790 | "aliases": [],
791 | "minimum-stability": "stable",
792 | "stability-flags": [],
793 | "prefer-stable": false,
794 | "prefer-lowest": false,
795 | "platform": [],
796 | "platform-dev": []
797 | }
798 |
--------------------------------------------------------------------------------