I am new to wordpress. My site had been posting scheduled posts, but it seems to stopped due to no traffic. So I disabled wp default cron, and setup a cron job via cPanel.
via command
wget -q -O - http://1pm.today/wp-cron.php?doing_wp_cron
And
usr/bin/curl --user-agent cPanel-Cron http://1pm.today/wp-cron.php?doing_wp_cron
But running wp-cron.php like this doesn't seem to trigger scheduled post.
I even tried to trigger cron job from a browser (not sure if it is the right way)
http://1pm.today/wp-cron.php?doing_wp_cron
But none of this trigger publish any scheduled post. Should cron job like this suppose to publish scheduled post? If so, any advice to debug this would be greatly appreciated, I will try to work with the tech support as the site is on a shared host.
I have added echo statement in wp-cron.php
function _get_cron_lock() {
global $wpdb;
$value = 0;
if ( wp_using_ext_object_cache() ) {
/*
* Skip local cache and force re-fetch of doing_cron transient
* in case another process updated the cache.
*/
$value = wp_cache_get( 'doing_cron', 'transient', true );
} else {
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) );
if ( is_object( $row ) )
$value = $row->option_value;
}
return $value;
}
if ( false === $crons = _get_cron_array() )
die();
$keys = array_keys( $crons );
$gmt_time = microtime( true );
echo "$keys[0] > $gmt_time";
if ( isset($keys[0]) && $keys[0] > $gmt_time )
die();
echo ":6c";
// The cron lock: a unix timestamp from when the cron was spawned.
$doing_cron_transient = get_transient( 'doing_cron' );
echo "7";
And the output is
1465529020 > 1465525264.31 without reaching ":6c"
So it die()
s because of
if ( isset($keys[0]) && $keys[0] > $gmt_time )
1465529020 > 1465525264.31
May I ask where $keys[0]
came from?
I am guessing the $key[0]
is a timestamp of the first cron job and $gmt_time
is the current time, and if $key[0]
is in the future and it should abort.
I already have a lot of "miss scheduled" post, so I am trying to better understand _get_cron_array()
but I don't get what's going on in `wp-includes/cron.php.
It seems that _get_cron_array()
has something to do with cron in wp_options
SELECT *
FROM `wp_options`
WHERE `option_name` LIKE '%cron%'
At this point, I am even more confused, as I can't figure out how a scheduled post is linked to the cron job.