Try New Technology

Using “curl” instead of “php -q” in a cronjob for wp-cron.php

by on Mar.01, 2014, under Techie

I found that a website running WordPress can become loaded down with a lot of page loads because wp-cron.php is called everytime, and on a site that isn’t and “active” blog it is not needed. In those cases it is helpful to the server load and page loads to disabled wp-cron.php from being ran automatically and set it up as a cronjob. See the below options to do this:

  • Edit the wp-config.php file
  • Disable the wp-cron.php from automatically running by going to the bottom of the database settings in wp-config.php (around line 37).
  • Add the code:
    define('DISABLE_WP_CRON', 'true');

    Directly under the define('DB_COLLATE', ''); like:

    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');

    define('DISABLE_WP_CRON', 'true');

  • Save the file wp-config.php file.
  • Add a cronjob (via Cron Job in your Control Panel, or crontab via CLI) with something like the following and set it to run every 6 hours or so:

You may have found the similar advise to what I wrote above on other web sites they will generally use “php -q” to run the wp-cron.php fil. Now the side-affect this can produce when using “php -q” vs “curl” (or “wget”) to call the wp-cron.php in your Crontab/Cronjob is you might start getting an error_log file with “Cannot send session cookie – headers already sent in” if one of your plugins or a file that is being ran by the cronjob has a session_start() call in the code such as Nivo Slider does.
Example (found around line 19 of nivo-slider.php):
if ( !session_id() ) session_start();

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...