X-Cart:Cron.php - Script for Periodic Tasks

From X-Cart 4 Classic
Revision as of 19:05, 22 February 2018 by Dohtur (talk | contribs)
Jump to: navigation, search

X-Cart provides a script cron.php which you can use to launch execution of periodic tasks.

The tasks include:

  • Checking whether authorization has expired for any payment transactions in Pre-authorized status and setting the status of the respective orders to Declined.
  • Checking whether authorization is going to expire for any payment transactions in Pre-authorized status and sending email notifications thereof to the store's Orders department.
    Note: You can define how many days in advance such notifications must be sent using the setting 'Number of days in advance that you want a reminder to be sent to the Orders department email address about an order in Pre-authorized status for which the authorization period is going to expire' in the 'General settings/General options' section.
  • Sending out survey invitations (when X-Survey add-on module is used).
  • Sending out abandoned cart reminder notifications (when Abandoned Cart Reminder add-on module is used in automated mode).

To run the script cron.php, use one of the following methods:

  • Use system cron to launch cron.php from the command line (via crontab).
  • Configure X-Cart to launch cron.php automatically.

The first method - launching the script from the command line via crontab - enables you to exactly set the time when the script needs to be launched.

The second method relies on X-Cart's session mechanism: it enables you to specify the frequency of cron.php execution in connection with X-Cart user sessions (The script will be launched once per a predetermined number of user sessions. You set the number

of sessions, "N", and the script cron.php is launched automatically every N-th user session).

If you decide to configure X-Cart to launch cron.php automatically in connection with user sessions, you will only need to adjust the setting 'Run the script that launches execution of periodic tasks once per N user sessions' in the 'General Settings/General options' section specifying the desired number of user sessions.

If you choose to launch the script from the command line, be sure to:

  • Set a secret key for running cron.php. This can be done using the setting 'Key for launch of the cron.php script' in the 'General Settings/General options' section of X-Cart Admin.
  • Keep the field 'Run the script that launches execution of periodic tasks once per N user sessions' in the 'General Settings/General options' section set to the default value of "0" (zero). This tells X-Cart that you do not wish it use the sessions mechanism to determine when to run cron.php and that you are going to use an external scheduler to launch this script.
  • Run the script cron.php from the command line (for example, via crontab) no more than once every 30 minutes.

Here's an example of a command to launch cron.php:

cd /var/www/vhosts/yoursite.com/httpdocs/xcart; /usr/bin/php -d safe_mode=Off cron.php --key=c901d65fc15ff15d0ac0af967437d051

Note that you need to run cron.php using the so called "CLI" version of PHP. Ask your hosting administrator to tell you the location of PHP CLI on your server and configure cron to run the cron.php script using PHP CLI version.


Important: We strongly recommend launching cron.php from the command line over allowing X-Cart to launch it in connection with user sessions. A launch of cron.php by X-Cart "once per N user sessions" may result in major site performance issues for the user of every Nth session (increased page load times and the like). A launch from the command line, on the opposite, will not interfere with any specific user session; the overall server load will increase but slightly (equivalent to one more user browsing the site) and is likely to go unnoticed by the majority of users.

See also