Reducing CPU usage for WordPress users!

WordPress is one of the most demanding content management system of recent days. Most of the users these days use wordpress for their blogs or websites. Around 85% sites of our servers are using wordpress and most of the clients are utilizing multiple wordpress blogs for their business. WordPress has been found to be using pretty good sum of CPU and Memory. Today’s shared hosting environments are more limited based on the CPU and memory rather than the Space and Bandwidth. It is always a wiser choice to spend little amount of time to reduce the overall cpu usage. This makes the blog running faster and hosting companies feel good to host sites which are nicer to their CPUs 🙂 Here are some tips to reduce the CPU usage on a wordpress blog and improve the site performance.

One of the first plugin I suggest all the wordpress users to install is “wp-super-cache”. You can download this plugin here:

http://wordpress.org/extend/plugins/wp-super-cache/

It is pretty easy to install. But a documentation can always be found in wordpress site:

http://wordpress.org/extend/plugins/wp-super-cache/installation/

wp-super-cache is the fastest caching plugin for wordpress blogs. It is always better to serve it from cache instead of running select command for each user of your blog. Enabling super cache would potentially reduce the cpu usage around 60-75%. One thing you should make sure that you are not using multiple caching plugin. I have seen couple of users think using multiple caching plugin would provide better result, but probably it is a bad idea for your blog to mix up both caching algorithm and result a potential mess.

If you are running scheduled posts on your blog, then it is probably a better idea to run wp-cron.php using cronjobs. WordPress calls wp-cron.php each time a user comes into your blog which is fairly a stupid idea. I am not sure why wordpress does so, but calling it once a 2 hours seems enough. You can set the cronjobs from cpanel. To set the cronjobs every two hour, you would need to set the timing something similar to the following:

0 */2 * * *

This would run at the very first minute of each even hours of the day. In the command section use something similar:

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

Replace cpanelusername with your original cpanel username. If you have added the blog as addon then probably, wp-cron.php is not in the public_html, but in a subfolder, so you would need to change the path accordingly, something similar to the following:

/home/cpanelusername/public_html/addondomain.com/wp-cron.php

A very well written article regarding the High CPU usage of wp-cron.php can be found here for your reference:

WordPress 2.6: The issue of “wp-cron.php”

Two more interesting plugins which are frequently used by the clients can cause excessive CPU usage, they are “All in SEO Pack” and “Featured Gallery Plugin like Nextgen”. If you have no other option than using a gallery, then probably, you would have to stick with the Gallery, but I strongly suggest not to use all in seo pack. Using all these modules one by one is better than using this all in one plugin. A very well written article for WordPress SEO can be found here and I suggest you better read it before blindly installing All in one SEO pack:

WordPress SEO

A good percentage of users run autoblogs. Autoblogs are pretty popular in these days with wordpress. Autoblogs tends to take high CPU with their cron executions. There isn’t much you can do to reduce those certain high cpu usage time to time but a better idea to set the cronjobs at odd timing. For example setting the cron to run at 17 minutes of each hour may improve the performance instead of setting it at very first minute of the hour. Most of the users tend to use their crons at very first minute. It sometimes cause a little load issues when lots of cron tries to run at the same time. So using odd timing is truly a pretty decent idea for both parties. You should also find the best timing interval for your autoblog updates. A reasonable gap of 2-4 hours is always a better idea as it reduces the frequency of your cronjob. But if you have no other option than running it every hour, then just don’t think, put it for every hour 🙂

For any sort of additional help, please post a comment. We at Mellowhost, provide absolute free consultation of reducing high CPU usage. Moreover, we would be pretty happy to install all the module and reconfigure your blog to make sure it takes less CPU and loads faster. So never hesitate to contact us for help 🙂

27 thoughts on “Reducing CPU usage for WordPress users!”

  1. This is probably the simplest definition of reducing the cpu and memory load on a server that I’ve read to date, in regards to WordPress. I’ve been encountering many, many complain emails from my hosting agent, because of the dreaded wp-cron.php and I tried everything else, including using tools like wp super cache and the such. To no avail, it shifted from being cpu usage to memory usage. Ahhhh! Well, I’ve setup the wp-cron.php to fire only once per 2 hour span instead of every 5-10 minutes that was occurring at the moment. I will see how good the results are but I’d love to hear the comments of others in this regard. I’m just very surprised at the excessive load that wp-cron does put on a server, especially with version 3.0 and beyond. I think that the only thing that may trouble me is that I do run a ton of automated tasks on a post moving to a published status and I’m hoping that I don’t break that as well.

    Thanks again,

    Frank

  2. Hello Frank, If you have configured everything properly then you shouldn’t. Let me know the result, if you are having any sort of unusuallities, let me know. Hope to get a solution for you.

    Dave

  3. Yep, still struggling with it. Seems to be firing less on cpu but much more on memory usage. Not sure what’s up there. I’m thinking of seeing if there is a way to remove outside access to the file, so only the manual cron will fire it.

    Frank

    1. Supercache would definitely help to reduce the memory usage. But I haven’t seen users facing memory usage issues with wordpress as wordpress has pretty damn simple structure unlike joomla or other cms. The only reason, you are facing those memory usage is some sort of additional plugins, are you having any statistical plugins?

  4. I have tried to do this as currently blog is hogging up my server, using more than 154Mb ram (cap is 150)…

    Set a cronjob to run every 2hrs, which runs /wp-cron.php but it seems the cron is still running on page load, as I am getting CSF emails still.

    I did add the define(’DISABLE_WP_CRON’, true); line to wp-config.php too so slightly confused what I have missed…

    Running standalone, latest version of WP.

    Any help much appreciated!

    1. Hello Dan,
      Couple of things you should try to consider here.
      1. wp-cron.php can hang even if you run with cronjobs for a long time time if it is unable to complete the process. Usually, you would need to “strace” the process to drag what is really happening there. Although, above techniques should prevent your wp-cron.php from bursting on each page load.
      2. If you find wp-cron.php still running on the cronjobs, you should try removing the cronjobs and wait a couple of hours to see if that makes any change or not. If it doesn’t, then the matter may lie somewhere else.
      3. If Disable cron option fails, try adding the rule in mod_security. This would certainly stop executing wp-cron.php on each page load.
      4. Try investigating your server a little more, are you using supercache? A supercache plugin can reduce significant memory and cpu usage.

      Let me know the result. Good luck.

  5. Using supercache, and i know its not just the cronjob set one running as that shows as php -q /scriptpath verses /usr/php etc /scriptpath when it runs by page view. :/

    I had a look in wp-cron but doesnt seem to check for the disable constant?

  6. It should work according to wordpress documentation. If it is failing, did you try editing cron.php or the mod_security technique?

  7. It seems the issue was because I copied the code line off the website it used ` instead of ‘ changed, and now seems to be working fine! 😀

  8. hello,

    i have tried all of them,

    at wp-cron.php (at top ) i have inserted

    define(‘DISABLE_WP_CRON’, true);

    changed this line

    if ( !empty($_POST) || defined(‘DOING_AJAX’) || defined(‘DOING_CRON’) )
    die();

    with

    if ( defined(‘DOING_AJAX’) || defined(‘DOING_CRON’) )
    die();

    at wp-config.php inserted this line :

    define(‘DISABLE_WP_CRON’, true);

    at cron.php

    //spawn_cron( $local_time );

    if ( strpos($_SERVER[‘REQUEST_URI’], ‘/wp-cron.php’) === false || ( defined(‘DISABLE_WP_CRON’) && DISABLE_WP_CRON ) )
    return;

    i am using w3tc,

    but after 30 min , nothing is happening, have i done smth wrong ?

    Waiting for an answer if is possible

    Thanks

  9. Hello!

    I’m seeing a lot of load from my wp-cron, but I’m not sure it’s too high. Seeing how you said it could be turned off, makes me wonder, what does wp-cron actually do that’s good?

    Also, I have no cpanel. Where is wp-cron called from, and if you are able to use cpanel to limit it, how can I limit it only using PHP?

    1. Hello,

      You would need to edit your wp-config.php file to stop it firing automatically. You can find in your FTP root.

      Until you are automating anything on your blog, you do not need wp-cron.php. If you are, then your best bet to run it using a custom cronjobs at regular interval or may be once a day.

      Good luck.

  10. hi dave.
    Thank you for this useful article.
    I just want to ask you that , does CPU usage affect us when the website articles gradually increased? I mean the articles quantity by it self(with out increased traffic or other factors) has any relation with the cpu usage?

    Thank you again.

  11. First I would like to congratulate the post. Good to be Brazilian may be that my English is not the melhroes, but I’m here to ask for help with my blog.
    My blog is a semi dedicated server (VPS) and as I have about 15 000 visits per day, I am going through a serious problem. CPU overhead has left my blog for a long time off the air and I do not know what to do and why I come here to see if someone can help me with this or at least to find the problem. Thank you for your attention and waiting for a contact.

  12. Can you please explain me .. how can i do it… last day my hosting provide stop my website… i have already wp3 cash install…and tell me how can i use this plugin and how can i stop wp.cron.php ..

    1. wp-cron.php is a scheduler for wordpress. Its primary task is to perform scheduled operation for example, posting pre-scheduled posts or clearing caches if using a cache plugin. Anything that has a scheduler involved would use the wp-cron.php

      Good luck.

    1. You do not really need an alternative. Whatever wordpress is perfectly optimized for onsite optimization. You should always avoid using an additional plugin.

  13. Hi!

    I’m having a similar problem, i have w3 total cache, everything works good, but the only problem is with HUGE amount of processes used, noticed in Cpanel.
    most of the time is over 20… from 25.

    This doesn’t happen all the time has some periods when works fine….

  14. Be careful, on the plugin official page, it is writing :

    Will the Super Cache compression slow down my server?
    No, it will do the opposite…

    WP-super-cache do not reduce the CPU usage… !!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.