nativeInstallerwordpress-multisite

Disable scheduled tasks

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). Learn more.

The wp-cron.php script will run once a user visits your site. If you get a lot of traffic, this could be a problem. This cron task is really necessary when you make updates in the blog. You can move this cron script to a system cron task to help lower resource usage on the server.

Disable the wp-cron.php script in the installdir/apps/wordpress/htdocs/wp-config.php file. The location is important - add the line below just before the database settings:

 define('DISABLE_WP_CRON', true);

Then, add the cron task to the system. There are two options:

  • Create a cron task for each WordPress site and set a different execution interval for each. For example, the cron tasks shown below will run every 15 minutes and 30 minutes respectively. This is fine if there aren’t a large number of sites.

    $ sudo crontab -u daemon -e
    */15 * * * * wget -q -O - "http://our-planets.com/wp-cron.php?t=`date +\%s`" > /dev/null 2>&1
    */30 * * * * wget -q -O - "http://earth.com/wp-cron.php?t=`date +\%s`" > /dev/null 2>&1
    
  • Create a unique cron task for all the domains and share the execution interval. This option is better if you have a large number of WordPress sites and all of them share the same tasks.

    • Create the following script at installdir/apps/wordpress/wp-cron-multisite.php:

      <?php
      require('installdir/apps/wordpress/htdocs/wp-load.php');
      global $wpdb;
      
      $sql = $wpdb->prepare("SELECT domain, path FROM $wpdb->blogs WHERE archived='0' AND deleted ='0' LIMIT 0,300", '');
      
      $blogs = $wpdb->get_results($sql);
      
      foreach($blogs as $blog) {
      
          $command = "http://" . $blog->domain . ($blog->path ? $blog->path : '/') . 'wp-cron.php';
          $ch = curl_init($command);
          $rc = curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
          $rc = curl_exec($ch);
          curl_close($ch);
      }
      ?>
      
    • Set the correct permissions:

      $ cd installdir/apps/wordpress/htdocs/
      $ sudo chown bitnami:daemon wp-cron-multisite.php
      
    • Add the task to the system crontab. For example, this cron task will run the script for each domain every hour. Add it using the following command:

      $ sudo crontab -u daemon -e
      0 * * * * wget -q -O - "http://our-planets.com/wp-cron-multisite.php?t=`date +\%s`" > /dev/null 2>&1
      

For more information, refer to this blog post.

Last modification September 4, 2018