﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
19818	ALTERNATE_WP_CRON causes some cron tasks to fail	norocketsurgeon	ryan	"If ALTERNATE_WP_CRON is defined as true and a task run by it requires certain global variables the task will fail.  I have traced this issue to a difference in the execution flow between a normal cron call and an ALTERNATE_WP_CRON call.  Normal cron calls actually wait for the entire execution flow of require_once('./wp-load.php'); to complete before processing tasks.  ALTERNATE_WP_CRON calls result in the execution of the tasks on the action 'sanitize_comment_cookies' which means some globals that may be required are not defined yet.  Below is a general outline of the execution flow of the two different types of cron calls.

Normal Cron:
* 'sanitize_comment_cookies' triggers wp_cron()
* wp_cron calls spawn_cron()
* spawn_cron() makes remote post to wp-cron.php on same site
* wp-cron.php defines 'DOING_CRON'
* wp-cron.php calls require_once('./wp-load.php');
* wp-settings.php fires action 'sanitize_comment_cookies'
* 'sanitize_comment_cookies' triggers wp_cron()
* wp_cron() calls spawn_cron()
* spawn_cron() detects 'DOING_CRON' defined and returns
* the rest of wp-load.php execution finishes resulting in all globals defined
* '''wp-cron.php executes tasks'''

ALTERNATE_WP_CRON:
* 'sanitize_comment_cookies' triggers wp_cron()
* wp_cron calls spawn_cron()
* spawn_cron() requre_once's wp-cron.php
* wp-cron.php defines 'DOING_CRON'
* '''wp-cron.php executes tasks before all globals are ready'''

I noticed this problem because ping processing requires the global wp_rewrite to be defined in some cases and since this is defined after the 'sanatize_comment_cookies' action is fired, pings to sites with fancy permalink structures will fail.  This failure occurs in the call to url_to_postid() in the pingback() function in wp-inclues/comment.php.  url_to_postid() attempts to process the pingback link and in cases where there are no post parameters requires $wp_rewrite to be defined.

How to reproduce:
* define ALTERNATE_WP_CRON to true
* configure site to send and receive pings and trackbacks
* create a post with a link to a blog that uses pretty permalinks (http://example.com/example/ would cause the failure but http://example.com/?p=1 would not)
* publish post
* no ping will be sent

My idea for a solution would be to put cron task execution inside a function called on the 'wp_loaded' action to ensure everything is setup before running the tasks.  I would be willing to implement this if someone more experienced / knowledgeable about cron thinks that this is appropriate."	defect (bug)	closed	normal	3.4	Cron	3.3	normal	fixed	has-patch commit	norocketsurgeon ian_dunn@… r-a-y@…
