Cron schedule not updating after run

Cron-jobs are incredibly slow in my website.

I created this small script, outside of the Wordpress environment, just to test the response time of WP Cron:

?php

//Method which does a basic curl get request
function get_data($url) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        //getinfo gets the data for the request
        $info = curl_getinfo($ch);
        //output the data to get more information.
        print_r($info);
        curl_close($ch);
        return $data;
}

get_data('http://www.example.com?wp-cron.php?doing_wp_cron=1486419273');

These are the results:

Array
(
    [url] = http://www.example.com/?wp-cron.php?doing_wp_cron=1486419273
    [content_type] = 
    [http_code] = 0
    [header_size] = 0
    [request_size] = 0
    [filetime] = -1
    [ssl_verify_result] = 0
    [redirect_count] = 0
    [total_time] = 42.822546 // Important
    [namelookup_time] = 0
    [connect_time] = 0
    [pretransfer_time] = 0
    [size_upload] = 0
    [size_download] = 0
    [speed_download] = 0
    [speed_upload] = 0
    [download_content_length] = -1
    [upload_content_length] = -1
    [starttransfer_time] = 0
    [redirect_time] = 0
    [certinfo] = Array
        (
        )

    [primary_ip] = 
    [primary_port] = 0
    [local_ip] = 
    [local_port] = 0
    [redirect_url] = 
)

As you can see it has an incredible load time of almost 43 seconds.

These are my Crons as reported by Crontol plugin:

The biggest problem I see here is that the Next run is not updating, meaning every cron runs every time... That's probably what's making it so slow, isn't it?

How to make the Next run actually changes according to the cron's Recurrence?

Topic wp-cron cron Wordpress

Category Web


You can use wp-cli to execute schedules without the detour via http request. Add in crontab -e.

*/30 * * * * wp cron event run --path=/path/to/wp-docroot

By this you wont run into maximum execution time problems which could be the reason why you schedule execution got stuck.


Well, I did it with manual crons.

I use NGINX + PHP-FPM, which makes it harder to do manual cron tasks. So I had to go with wget to achieve it.

If you use PHP-FPM and need to trigger Wordpress's cronjobs via crontab, do:

  1. Login to SSH with root.
  2. Run crontab -e
  3. Add */30 * * * * /usr/bin/wget -q -O /tmp/temp_crons.txt http://example.com/wp-cron.php?doing_wp_cron

Where 30 is 30 minutes. It saves the cron results to temp_crons.txt

Well, it's working:

enter image description here

If you use Apache, just do a regular cron with /usr/bin/php

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.