Three days ago arvixe telling my site using to much their cpu usage. They complaint about wp-cron.php and index.php process which I believe it was looping and won’t stop in background. wp-cron is just like cron job in normal condition. The crazy thing everyone doesn’t know is, it’s loading each time visitors coming to their site. I don’t know why wordpress don’t fix it or at least give options to run it each time frame.

For a site using wordpress and have a lot articles/pages the optimization for it is just disable wp-cron, another option is disable wp-cron and running cron job from cpanel which can be setup in time frame.

You will lose schedulle post feature but it’s better than get suspended right? You still can run cron in time frame you setup from cron job panel than using crazy method like spawn it each time visitors coming to your site. Let’s do this thing, it’s very easy…

[to_plus]

  1. Open your wp-config.php and put this after the <?php. define(‘DISABLE_WP_CRON’, true);
  2. Open wp-includes folder and find a file with name cron.php
  3. Find string “function wp_cron() {
  4. Replace all function with code below :
    function wp_cron()
    {// Prevent infinite loops caused by lack of wp-cron.php
    if ( strpos($_SERVER[‘REQUEST_URI’], ‘/wp-cron.php’) !== false || ( defined(‘DISABLE_WP_CRON’) && DISABLE_WP_CRON ) )
    return;if ( false === $crons = _get_cron_array() )
    return;$local_time = time();
    $keys = array_keys( $crons );
    if ( isset($keys[0]) && $keys[0] > $local_time )
    return;$schedules = wp_get_schedules();
    foreach ( $crons as $timestamp => $cronhooks ) {
    if ( $timestamp > $local_time ) break;
    foreach ( (array) $cronhooks as $hook => $args ) {
    if ( isset($schedules[$hook][‘callback’]) && !call_user_func( $schedules[$hook][‘callback’] ) )
    continue;
    // spawn_cron( $local_time );
    break 2;
    }
    }
    }
  5. Save it/replace cron.php file with the new edited cron.php
  6. Done

After doing this your wp-cron has been disabled and never ever run each time a visitors coming to your site. But you will lose schedulle post, to fix this problem open your hosting control panel and set cron job from there to run your wp-cron.php. You can set it run each 24 hours or in time frame you need.

After doing this small optimization arvixe not complaint to me. It’s mean this is maybe the big issue for worpdress to update their cron setting.

That’s a share for today, have a great day everyone, and Happy New Year! 😀

[/to_plus]

 

Similar Posts:

Related Search Terms:

    Digg Del.icio.us StumbleUpon Reddit Twitter RSS

If you're new here, you may want to subscribe to my RSS feed. You may copy or publish this article to your blog or other site as long you give credit link back to this site article. Thanks for visiting my blog!