Last active
August 29, 2015 14:24
-
-
Save dmsmidt/0a651945809a7686b0b2 to your computer and use it in GitHub Desktop.
Drupal 7 Drush Cron Verbose (with timing)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Can be called with '$ drush php-scrip /path/to/dcron.php' | |
global $timers; | |
$hook = "cron"; | |
$return = array(); | |
$queues = module_invoke_all("cron_queue_info"); | |
drupal_alter("cron_queue_info", $queues); | |
foreach (module_implements($hook) as $module) { | |
$function = $module . "_" . $hook; | |
print($function . " - "); | |
timer_start($function); | |
$result = call_user_func_array($function, array()); | |
if (isset($result) && is_array($result)) { | |
$return = array_merge_recursive($return, $result); | |
} | |
else { | |
if (isset($result)) { | |
$return[] = $result; | |
} | |
} | |
timer_stop($function); | |
print($timers[$function]["time"] . "ms\r\n"); | |
} | |
foreach ($queues as $queue_name => $info) { | |
DrupalQueue::get($queue_name)->createQueue(); | |
if (!empty($info["skip on cron"])) { | |
continue; | |
} | |
$function = $info["worker callback"]; | |
print("Queue: " . $function . " - "); | |
timer_start($function); | |
$end = time() + (isset($info ["time"]) ? $info ["time"] : 15); | |
$queue = DrupalQueue::get($queue_name); | |
while (time() < $end && ($item = $queue->claimItem())) { | |
try { | |
// Uncomment to see timing per queue item (gives a lot of output) | |
//timer_start($function . "_item"); | |
$function($item->data); | |
$queue->deleteItem($item); | |
//timer_stop($function . "_item"); | |
//print($item->id . $timers[$function . "_item"]["time"] . "ms - "); | |
} | |
catch (Exception $e) { | |
print($e->getMessage()); | |
} | |
} | |
timer_stop($function); | |
print($timers[$function]["time"] . "ms\r\n"); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This can be pasted and run in the terminal directly. | |
drush php-eval 'global $timers; $hook = "cron"; $return = array(); $queues = module_invoke_all("cron_queue_info"); drupal_alter("cron_queue_info", $queues); foreach (module_implements($hook) as $module) { $function = $module . "_" . $hook; print($function . " - "); timer_start($function); $result = call_user_func_array($function, array()); if (isset($result) && is_array($result)) { $return = array_merge_recursive($return, $result); } else { if (isset($result)) { $return[] = $result; } } timer_stop($function); print($timers[$function]["time"] . "ms\r\n"); } foreach ($queues as $queue_name => $info) { DrupalQueue::get($queue_name)->createQueue(); if (!empty($info["skip on cron"])) { continue; } $function = $info["worker callback"]; print("Queue: " . $function . " - "); timer_start($function); $end = time() + (isset($info ["time"]) ? $info ["time"] : 15); $queue = DrupalQueue::get($queue_name); while (time() < $end && ($item = $queue->claimItem())) { try { $function($item->data); $queue->deleteItem($item); } catch (Exception $e) { print($e->getMessage()); } } timer_stop($function); print($timers[$function]["time"] . "ms\r\n"); }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment