-1

I have Apache Error coming from /wp-cron.php. I didn't modify that file. How can I avoid the timeout?

  • 1
    You need to find which cron job fomr your plugins is causing the timeout. Also, try wp-cron control, it is awsome to avoid rare conditions resulting in multiple execution of wp-cron at the same time, which can be (I can not know) the cause of your problem. – cybmeta Mar 8 '16 at 7:55
  • @cybmeta I'll try first the my answer I'll try to find which of the plugin cause it. I need to keep my plugin. Thanks anyway. – Jows Mar 8 '16 at 8:06
0

WordPress uses a file called wp-cron.php as a virtual cron job, or scheduled task in order to automate things like publishing scheduled posts, checking for plugin or theme updates, sending email notifications and more.

By default WordPress is setup to call wp-cron.php everytime someone visits your WordPress website when a scheduled task is present, to basically ask "is it time to do anything yet?".

On low traffic sites this is perfectly fine, but when visitors roll in, checking multiple times for scheduled tasks can be very inefficient and lead to resource usage problems for your server, plus make your website load slower.

Disable default wp-cron.php behavior

We can easily tell WordPress to let us handle the execution of wp-cron.php with the wp-config.php file.

Open your wp-config.php file with the cPanel File Manager Code Editor Go to the bottom of the database settings in wp-config.php typically around line 37.

Add the code below :

define('DISABLE_WP_CRON', 'true');

Setup manual cron job for wp-cron.php

We don't want to leave WordPress without any ability to automate tasks it might need to do. But at least now that it's not running for every single visitor, we can have way more control over when these tasks take place.

For most WordPress users having the wp-cron.php script run every 6 hours is perfectly fine. That would be just 4 executions in a day, compared to possibly hundreds, or even thousands if you had a lot of website traffic that day.

  1. Log into cPanel
  2. Under the Advanced section, click on Cron Jobs.
  3. Select Once an hour from the Common Settings drop-down.
  4. Now select Every 6 hours from the Hour drop-down.
  5. Finally fill in the code to run our cron job and click Add New Cron Job.

    • cd /home/userna5/public_html; php -q wp-cron.php
    • Where userna5 is your cPanel user name.

    • Keep in mind that the /home/userna5/public_html path would be for a primary domain, if you're using an addon domain, or have WordPress installed in a sub-directory you'll want to be sure to update your path.

  6. You should see that your new cron job was added successfully.

http://www.inmotionhosting.com/support/website/wordpress/disabling-the-wp-cronphp-in-wordpress

| improve this answer | |
  • 6 hours is very high, suitable only for very low dinamic websites; it can not be a general recommendation. Also, wp-cron.php is a PHP script not suitable to be executed through php-cli. You should execute it through wget command; otherwise you can end up with troubles. For example, executing it through php-cli sets max execution time to unlimited which leave the door open to cron jobs with errors or wrong coded, like you seem to have, be open forever until your server crush. – cybmeta Mar 8 '16 at 8:30
  • @cybmeta I can't follow. What should I do if your telling its not recommended. – Jows Mar 8 '16 at 8:46
  • 6 hours can be good for you, I just said it can not be a general recommendation. For me it is 5 minutes. If 6 hours is good for you, just use it. But I really recommend to execute wp-cron.php through wget and not through php-cli command. – cybmeta Mar 8 '16 at 9:52
  • If the problem is with the entries in wp-cron's scheduled tasks (cause of timeouts), simply adding them elsewhere may not help. We need to know what's causing the timeout to troubleshoot reliably. – Sas3 Oct 2 '17 at 2:30
  • this answer is totally backward. wordpress cron is problematic on low traffic sites, but it should work well on high traffic sites. The cause for your errors is most likely bad code in your plugins or theme. If you have an actual process that needs more time to somplete, a much better way it to just change its php timeout in the code. a cron running every 6 hours is totally ridiculous and sooner or later will break something. – Mark Kaplun Oct 2 '17 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.