getDefaultSettings(); if (!$settings['launcher']) { return; } $launcher = _ultimate_cron_plugin_load('launcher', $settings['launcher']); if (!$launcher) { watchdog('ultimate_cron', 'Invalid poormans cron launcher: @name', array( '@name' => $settings['launcher'], ), WATCHDOG_ERROR); return; } if ($settings['early_page_flush']) { // Poormans cron needs to be the last that runs. // Run remaining exit hooks, and shutdown like core does. $modules = module_implements('exit'); do { $module = array_shift($modules); } while ($modules && ($module !== 'ultimate_cron')); foreach ($modules as $module) { module_invoke($module, 'exit', $dest); } // Commit the user session, if needed. drupal_session_commit(); if (variable_get('cache', 0) && ($cache = drupal_page_set_cache())) { drupal_serve_page_from_cache($cache); } _registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE); drupal_cache_system_paths(); module_implements_write_cache(); _ultimate_cron_launch_poorman($launcher); exit; } else { // Wait until the very end before running cron. register_shutdown_function('_ultimate_cron_launch_poorman', $launcher, 3); } } /** * Postponable poormans cron launching. * * @param UltimateCronLauncher $launcher * The Ultimate Cron launcher to use for poormans cron. * @param int $postpone * The number of times to postpone via register_shutdown_function. */ function _ultimate_cron_launch_poorman($launcher, $postpone = 0) { if ($postpone > 0) { register_shutdown_function(__FUNCTION__, $launcher, $postpone - 1); return; } // Poormans cron should run as anonymous, just like regular cron does. global $user; $original_user = $user; $user = drupal_anonymous_user(); $launcher->launchPoorman(); $user = $original_user; } /** * Flush the page and end the client request. */ function ultimate_cron_poorman_page_flush() { @ignore_user_abort(); $GLOBALS['ultimate_cron_page_flush'] = TRUE; while (ob_get_level() > 0) { ob_end_flush(); } flush(); // FastCGI may need another way of letting the client know, that // we're done with it. if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } } /** * Page callback for triggering poormans cron. */ function ultimate_cron_poorman_page() { if (!isset($_GET['cron_key']) || variable_get('cron_key', 'drupal') != $_GET['cron_key']) { watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE); drupal_access_denied(); } drupal_page_is_cacheable(FALSE); drupal_exit(); } /** * Send the actual HTTP request for launching threads. */ function ultimate_cron_poorman_trigger() { $url_options = variable_get('ultimate_cron_poorman_url_options', array()); $http_options = variable_get('ultimate_cron_poorman_http_options', array()); $url_options = array( 'query' => array( 'timestamp' => REQUEST_TIME, 'cron_key' => variable_get('cron_key', 'drupal'), ), 'absolute' => TRUE, ) + $url_options; $plugin = _ultimate_cron_plugin_require('settings', 'poorman'); $settings = $plugin->getDefaultSettings(); $http_options = array( 'headers' => array( 'User-Agent' => $settings['user_agent'], ), ) + $http_options; $url = url('admin/config/system/cron/poorman', $url_options); $response = drupal_http_request($url, $http_options); if (!empty($response->error)) { watchdog('ultimate_cron', 'Could not trigger poorman at @url. Error: @error', array( '@url' => $url, '@error' => $response->error, ), WATCHDOG_ERROR); } }