Skip to content

Instantly share code, notes, and snippets.

@jbrinley
Created February 19, 2014 14:42
Show Gist options
  • Save jbrinley/9093418 to your computer and use it in GitHub Desktop.
Save jbrinley/9093418 to your computer and use it in GitHub Desktop.
Adds 1M actions to the Action Scheduler queue, with 20K of them already due, and another 100 coming due each minute.
<?php
function action_scheduler_load_testing() {
/** @var wpdb $wpdb */
global $wpdb;
$sql = "INSERT INTO {$wpdb->posts} (post_author, post_date, post_date_gmt, post_content, post_title, post_status, post_name, post_modified, post_modified_gmt, post_type) VALUES ";
for ( $i = -200 ; $i < 9800 ; $i++ ) {
$date = new DateTime($i.' minutes');
$action = md5($i);
$fields = array(
0,
$date->format('Y-m-d H:i:s'),
$date->format('Y-m-d H:i:s'),
json_encode(array($i)),
$action,
'pending',
$action,
$date->format('Y-m-d H:i:s'),
$date->format('Y-m-d H:i:s'),
'scheduled-action',
);
$fields_sql = vsprintf( "( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", $fields );
$values = array_fill( 0, 100, $fields_sql );
$this_sql = $sql . implode(', ', $values);
$wpdb->query($this_sql);
}
}
include_once dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/wp/wp-load.php';
action_scheduler_load_testing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment