31

How to disable WordPress wp-cron

Posted by danblog on October 3, 2010 in General stuff, Scripts |

Recently I have been noticing that this blog has been eating its way through the servers ram like no bodies business, easily using more than 150mb before its automatically killed.

By default the wp-cron.php is run every single time a page is loaded, this includes admin pages. This can lead if you have a busy blog to a lot of cron runs, which simply aren’t needed.

What does the wp-cron do? You might ask, and even if you don’t I will tell you anyway. The wp-cron will do things like scheduled posts and can also include things that plugins want running.

So how we go about this is simple, we will disable the wp-cron from running on every page load, and then add a proper cron job.

First lets disable it:

Simply open wp-config.php and add the follow line.

define(‘DISABLE_WP_CRON’, true);

Note: You need to make sure you use an apostrophe instead of single quotes in the code here, otherwise it will not work!

Second, lets add the cron:

It is probably a good idea to run the cron job every couple of hours, for this we will add something like this.

0      */2      *      *      *

For the command you simply need to call the wp-cron either using wget OR php -q

php -q /home/cPanel_User/public_html/wp-cron.php

OR

wget http://YourDomain.com/wp-cron.php

Personally I’d prefer the php -q option as some hosts can have trouble resolving domains on the same server.

If anyone has any questions or comments please leave a comment below and I’ll try to help. 🙂

Tags: , , ,

31 Comments

  • Roms says:

    What if i chmod the wp-cron.php to 000? What negativ effect will this have?

  • Dan says:

    Hi, thanks for the comment!

    If you have it set to 000 I believe that means it is only accessible to root, and the owner (after changing permissions) this is likely to cause permissions problems when anything other than root (and perhaps the owner, although I doubt even that) tries to access – read/write to it.

    I’d suggest something like 744 (read by all, write and exec by owner).

  • Scott says:

    Thanks for this Dan. Quick question, if we disable wp cron do we HAVE to set up a regular cron? I don’t understand enough about crons to know. What would happen if we disabled wp cron but didn’t set up a cron on our server?

    Thanks

    • Dansgalaxy says:

      Hi Scott,

      The WP Cron job runs numerous operations which “need” to be run regularly, this includes scheduled posts, now as we have disabled the cron from running on page load this means scheduled posts won’t be published unless the cron is run an alternative way, as well as this there are other functions which the wp-cron performs and (i think) plug-ins may also run things via cron which they need.

      Easy answer, things might not work as expected or update as expected… So it’s a very good idea to set-up a cron job on the server if you are disabling the on-page-load option for WordPress.

      Hopefully this has answered your questions, Thanks for commenting! 🙂

      • Scott says:

        Hi Dan

        Many thanks! Yep, I think I get it now lol. Guess I’ll have to give it a try as I wouldn’t want any of my blogs not functioning properly.

        I’ll come back to your article when I’m ready to disable wp cron. Thanks again!

  • Scott says:

    Thanks for this Dan. Quick question, if we disable wp cron do we HAVE to set up a regular cron? I don’t understand enough about crons to know. What would happen if we disabled wp cron but didn’t set up a cron on our server?

    Thanks

    • Dansgalaxy says:

      Hi Scott,

      The WP Cron job runs numerous operations which “need” to be run regularly, this includes scheduled posts, now as we have disabled the cron from running on page load this means scheduled posts won’t be published unless the cron is run an alternative way, as well as this there are other functions which the wp-cron performs and (i think) plug-ins may also run things via cron which they need.

      Easy answer, things might not work as expected or update as expected… So it’s a very good idea to set-up a cron job on the server if you are disabling the on-page-load option for WordPress.

      Hopefully this has answered your questions, Thanks for commenting! 🙂

      • Scott says:

        Hi Dan

        Many thanks! Yep, I think I get it now lol. Guess I’ll have to give it a try as I wouldn’t want any of my blogs not functioning properly.

        I’ll come back to your article when I’m ready to disable wp cron. Thanks again!

  • Paul Kaser says:

    Thanks, Dan. Our Hostgator shared hosting account kept getting shut down, and I’m pretty sure wp-cron was the issue. I’ve used your tips here to fix things up proper.

  • Paul Kaser says:

    Thanks, Dan. Our Hostgator shared hosting account kept getting shut down, and I’m pretty sure wp-cron was the issue. I’ve used your tips here to fix things up proper.

  • Andrew says:

    There’s nothing wrong with HostGator! In fact, I use them over Linode now for my bigger clients.

  • Andrew says:

    There’s nothing wrong with HostGator! In fact, I use them over Linode now for my bigger clients.

  • […] making some changes a while ago to how I run the wp-cron on this blog I noticed some odd problems as scheduled posts weren’t being […]

  • Graham says:

    Thanks for the article Dan.

    One minor quibble: in the code to add to wp-config.php, you say:
    define(‘DISABLE_WP_CRON’, true);

    Note the quotes should actually be like this: ‘ . I copied and pasted from your article into my wp-config.php, and with the wrong quotes it doesn’t work.

    Thanks, Graham

    • Dansgalaxy says:

      Hi Graham, 

      Glad you like the post :)It should be using ‘ quotes, however i think it might be a quirk of WordPress that it changes them as this is something I have run into myself when copying and pasting similar code from blogs! – I’ve added a note to the post to hopefully save confusion in future. :)Dan

  • Jasontoews3434 says:

    Making the change in wp-config.php seems pretty straightforward, but I’m not clear how/where I add the new “every two hours” cron job. Can you give some details on that, or post a relevant link?

    Apologies; this is something new to me.

    • Dansgalaxy says:

      This would be dependant on your webhosting provider, and the control panel they use.

      If they use cPanel it should be fairly straight forward assuming you have permissions to set cronjobs there will be an icon within cPanel called Cron Jobs or similar which you can manage them there. 

      Hope this helps! Thanks for reading.

  • Dean says:

    Hi Dan…been having issues with HG closing one of my reseller accounts down because of usage issues and going to try your tip with the cron. They have disabled my wp-cron on each site on the account which saves me adding the disabled code. My question…I have about 20 sites on this account…do I use the same settings you’ve listed for each site when setting up the manual cron job in cpanel?

    Hope that makes sense? Thanks.

    Dean.

    • Dansgalaxy says:

      Assuming each site is a separate wordpress install then yes you’ll need to run the wp-cron.php for each install as (I assume) each will be running different code and connecting to different databases etc to perform their actions. 🙂

      • Dean says:

         Hi Dan…as I mentioned in the first comment, HG have disabled my wp-cron from their end which I suppose means I don’t have to add this disable code… define(‘DISABLE_WP_CRON’, true);

        I have set up the cron through my cpanel on one site as you suggest and I get an email every couple of hours when it runs. This is the message I get:

        Cron php -q /home/cPanel_User/public_html/wp-cron.php…No input file specified.

        Does this sound right? Is this because the wp-cron has been disabled? Sorry, just wondering if it looks right. Appreciate your help. Thanks.

        Dean.

        • Dansgalaxy says:

          It depends *how* HostGator in their wisdom has disabled wp-cron.php, it might be they have disallowed the wp-cron.php file from executing. Check your wp-config.php to see if the disable_wp_cron line has been added, if it’s not there chances are they disabled it by changing the file permissions on the wp-cron.php file or simply deleting the file.

          • Dean says:

             Ok..thanks. No, they have changed the file permissions. Do I still need to add the line of code?
            Appreciate the time you have taken to answer my questions.

          • Dansgalaxy says:

            I’d add it just to be sure, but you should ask how they disabled the cron as need to ensure you won’t run into issues due to whatever they have imposed. 

  • Jddean73 says:

    Hi Dan,

    Thanks for this information. Just to clarify. In this command:
     php -q /home/cPanel_User/public_html/wp-cron.php

    cPanel_User is replaced by the username of the database, correct?

    Just checking. Thanks.

    JD.

  • Rob Thrasher says:

    OK, so I never really paid attention to Updates or Update scheduling. why do I need to add code to the tab to poll every 60 minutes when right below Updates, there is a field that allows me to select to poll every so many minutes? I think my blogs get shut down every time the spiders come to crawl because they trigger updates, maybe???   What am I missing here? 🙂

  • ccmedia says:

    You say to add this line to the wp-config file but other articles say to add it to the top line of wp-cron itself? Does it make a difference

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2007-2017 Dan's Tech Blog All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.