Cron Job Issues

From WHMCS Documentation

Revision as of 20:02, 5 December 2019 by DanR (talk | contribs)

This page details some of the common problems and errors which might occur when running the WHMCS cron job.

Troubleshooting

There are several techniques available for troubleshooting problems which one may encounter with the cron job, in descending order of verbosity they are:

Run the cron job in your browser

Run the cron job from the server command line

  • Access your server command line
  • Copy the cron job command for the cron.php file from your server's cron tab
    crontab -u userName -l)
  • Execute the command you copied:
    php -q /path/to/whmcs/crons/cron.php
  • Examine the output for any errors.

Run the cron job from the server command line with debugging enabled

  • Ensure that Display Errors is enabled in your admin area from the Setup > General Settings > Other tab
  • Access your server command line
  • Confirm that display_errors is enabled in your command line PHP environment:
    php -i | grep display_errors
    display_errors => STDOUT => STDOUT
  • Copy the cron job command for the cron.php file from your server's crontab:
    crontab -u userName -l
  • Add the all --force -vvv flags to the end of the cron command and execute it:
    php -q /path/to/whmcs/crons/cron.php all --force -vvv
  • Examine the output for any errors
  • The final line output should be "[OK] Completed"

Common Errors

Site error: the file /path/to/crons/cron.php requires the ionCube PHP Loader ioncube_loader_lin_5.6.so to be installed by the website operator

Seeing this error output indicates that the PHP configuration for your WHMCS installation may be different than that used for the command line.

Please try running the following command at the server command line whilst logged in as the same user under which the cron job is running to see the version information for your PHP and ionCube configuration:

php -v

You should get an output along the lines of:

PHP 5.4.43 (cli) (built: Aug 2 2015 02:44:35)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with the ionCube PHP Loader v4.7.5, Copyright (c) 2002-2014, by ionCube Ltd.

If the "with the ionCube PHP Loader" line is absent, this indicates that the Ioncube loaders are not available for this user. Please work with your hosting provider or server administrator to ensure that the Ioncube loaders are available to the cron job user.

Unable to communicate with the WHMCS installation

This error occurs when the cron.php file is unable to communicate with the WHMCS installation, its typically occurs when the location of the /crons directory has been customised. The cron.php file will look for the WHMCS directory in the location specified in the /crons/config.php file. So to To resolve this error:

  • Open the /crons/config.php file
  • Ensure the $whmcspath line is uncommented by removing the preceding // characters.
  • Ensure the path specified on the $whmcspath is the full system path to your WHMCS directory. This is the directory which contains the init.php and clientarea.php files.
  • Once completed, the entire file will look like this:
<?php
/**
 * Custom Crons Directory Configuration
 *
 * This crons folder may be moved to any place above or below the docroot.
 *
 * We recommend locating it outside the docroot to prevent browser based access.
 *
 * Upon moving it, you must provide the path to your WHMCS installation to
 * allow the cron task files to communicate with the parent WHMCS installation.
 *
 * To do this, rename this file config.php, then uncomment and enter the full
 * path to the WHMCS root directory in the $whmcspath variable below.
 *
 * You must also provide the appropriate path to the crons folder in the
 * $crons_dir variable inside the WHMCS master configuration file.
 *
 * For more information please see http://docs.whmcs.com/Custom_Crons_Directory
 */

$whmcspath = '/home/username/public_html/whmcs/';

Could not open input file: /path/to/crons/cron.php

This error occurs when the cron.php file is not present in directory path specified. Check the path specified, and correct it as required, or, ensure the cron.php file is present, if it is not.

Oops! Something went wrong and we couldn't process your request

This indicates a fatal PHP error has occurred. Navigate to 'Setup -> General Settings -> Other' and tick 'Display Errors', then run the cron again and the full error should be shown. The error can be a multitude of things but normally indicate an issue with one or more modules, which should be referenced. An example of what you may see is:

<p class="debug">exception 'Whoops\Exception\ErrorException' with message 'Cannot redeclare class module_class' in /home/whmcs/public_html/modules/gateways/module-name/module-file.php:16<br />

If the error referenced is a third party module you are using, you will need to contact the developer(s) of the module to review and resolve the error. If the error reference is a WHMCS developed and shipped module, please contact our Support Team. It may also indicate an issue with the PHP configuration, and you will find the most common errors with the configuration in this documentation, such as the ones below.

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 20480 bytes)

This error indicates the cron is being terminated as it is hitting a 'memory_limit' of 32M. You will need to increase this to 64M (128M if possible) to resolve this. Please contact your server administrator or hosting provider for assistance with this. You can check the limit set using this command:

php -ini | grep "memory_limit"

The file /path/to/crons/cron.php is corrupted

This error can observed in version 7.5 and above. This error will occur if you are running Ioncube Loaders version 10.0 or earlier. WHMCS 7.5 requires Ioncube Loaders 10.1.0 or above. If your WHMCS installation is working, as described above, it indicates that the PHP configuration for your WHMCS installation may be different than that used for the command line. To check this, you can again use the command below:

php -v

Look for the following line to identify the ionCube loader version:

with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.2.0, Copyright 
(c) 2002-2018, by ionCube Ltd.

Error: Call to undefined function curl_init()

This error indicates your PHP configuration is missing the 'curl' extension, you can check if this is missing using the command below:

php -m

A similar error may also occur if the 'curl_init' function is a disabled function in your PHP configuration.

Whoops\Exception\ErrorException' with message 'Maximum execution time of 30 seconds exceeded

This error indicates the cron is being terminated as it is hitting a 'max_execution_limit' of 30 seconds. This will need to be increased depending on the size of your installation. A limit of '120' would suffice for most installations, but some may need '300'. The current limit can be checked with this command:

php -ini | grep "max_execution_time"

Segmentation fault

This error is not something directly related to the WHMCS software and can occur for multiple different reasons. It most commonly indicates a PHP crash is occurring and would suggest there is an issue with your PHP installation, for example a malfunctioning extension. It is something your server admin/hosting provider would need to investigate, using the 'strace' utility for example.

Domain renew link in emails is broken

Under some PHP/Server configurations the correct URL for the domain renew link in domain renewal reminder emails is generated incorrectly.

This can usually be fixed by using the correct PHP binary on your cronjob, or you can adjust the cronjob to work-around the issue by formatting your cron command as:

cd /path/to/crons/ & php -q cron.php