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 MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

NOTE: The Approach A sections referred to below do not apply to Bitnami native installers. Users of Bitnami native installers should refer only to the Approach B sections.

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 WordPress wp-config.php configuration file. The location is important - add the line below just before the database settings:

NOTE: Depending on your installation type, the WordPress wp-config.php configuration file can be found in the following locations:

  • Approach A (Bitnami installations using system packages): installdir/wordpress/wp-config.php

  • Approach B (Self-contained Bitnami installations): installdir/apps/wordpress/htdocs/wp-config.php

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 -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 as wp-cron-multisite.php at the WordPress installation directory:

      NOTE: Depending on your installation type, the wp-cron-multisite.php script should be in the following locations:

      • Approach A (Bitnami installations using system packages): installdir/wordpress/wp-cron-multisite.php

      • Approach B (Self-contained Bitnami installations): installdir/apps/wordpress/htdocs/wp-cron-multisite.php

        <?php
        require(__DIR__ . '/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:

        $ 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 -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 June 16, 2021