Close

How to Avert Timeout in WordPress Waiting for Output through CGI Script?

In WordPress, the wp-cron.php file is used as a means to automate scheduled tasks. It can be used to check theme/plugin updates, publish scheduled posts, manage email notifications, etc.

WordPress Waiting for Output through CGI Script

As per default settings, WordPress automatically calls this file (wp-cron.php), every time a visitor comes to your website when any scheduled task is there. Its purpose is to inquire whether there is something to be done.

This is absolutely fine when the traffic is low. The low traffic ensures the file is not called multiple times. However, when the traffic increases substantially, the checking process is undertaken multiple times making it a resource-heavy process. This can unnecessarily increase usage resource usage problems and even lead to server downtimes. No one likes a slow loading website.

How to Disable default wp-cron.php behavior

You can easily control the wp-cron.php file execution through the wp-config.php file. Here’s how:

  1. Open the wp-config.php file from the ‘cPanel File Manager Code Editor’.
  2. Now, move towards the bottom of the wp-config.php in the database settings.
  3. Most likely, you should look for line 37, where you have to add the below mentioned code:

define(‘DISABLE_WP_CRON’, ‘true’);

Manually Setting Up cron job for wp-cron.php

Now, you may leave WordPress with no ability to handle task automation wven when it needs to. With above change, WP won’t be running processes for every single visitor. Which means you can better regulate how and when the file will execute tasks.

As per our experience, most sites will be perfectly fine to run the process every 6-8 hours or so. This ensures that the process is executed around 3-4 times in a day. That, when compared to earlier hundreds of process executions, means the resource usage is far less. Here’s how you can set the timing of process execution.

  1. Log into the cPanel with valid username and password.
  2. Go to the ‘Advanced section’ and enter the ‘Cron Jobs’ by clicking on it.
  3. First, choose ‘Once an hour’ under the drop down in ‘Common Settings’.
  4. Next, select ‘Every 6 hours’ further under the ‘Hour’ drop-down menu.
  5. In the end, enter the code to execute our cron job and create a new Cron Job by clicking on ‘Add New Cron Job’.
    • cd /home/userna5/public_html; php -q wp-cron.php
    • Note: Here, enter your cPanel user name in place of userna5

Remember, that the /home/userna5/public_html is valid for your primary domain. In case, there is an additional domain, you will have to update the path in the sub-directory as well.

For more tips on WordPress, keep visiting our resources section.