Difference between revisions of "X-Cart:Cron.php - Script for Periodic Tasks"

From X-Cart 4 Classic
Jump to: navigation, search
m (Q:why is cli?A:https://sd.x-cart.com/view.php?id=74085#752742)
m
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
X-Cart provides a script <u>cron.php</u> which you can use to launch execution of periodic tasks.
+
X-Cart provides a script <u>cron.php</u> which you can use to launch the execution of periodic tasks.
  
 
The tasks include:
 
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 an 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.<br />{{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.}}
+
:* Checking whether an authorization is going to expire for any payment transactions in Pre-authorized status and sending email notifications thereof to the store's Orders department. See more info on the setting "Number of days in advance that you want a reminder to be sent..." [[X-Cart:General_Options#NumberOfDays|here]].
:* Sending out survey invitations (when X-Survey add-on module is used).
+
:* Sending out survey invitations (X-Survey).
:* Sending out abandoned cart reminder notifications (when Abandoned Cart Reminder add-on module is used in automated mode).
+
:* Sending out abandoned cart reminder notifications (Abandoned Cart Reminder in automated mode).
  
You can choose to launch the script <u>cron.php</u> from the command line or to set up X-Cart to launch this script automatically. Launching <u>cron.php</u> from the command line gives you a bit more control: you can decide exactly when you wish the script to be launched. Allowing X-Cart to launch this script automatically saves you time and effort: X-Cart will launch the script once per a predetermined number of user sessions.
+
To run the script <u>cron.php</u>, use one of the following methods:
 +
:* Run <u>cron.php</u> from the command line (For example, use system cron to launch <u>cron.php</u> via crontab).
 +
:* Configure X-Cart to launch <u>cron.php</u> automatically.  
  
If you choose to launch the script from the command line, you will need to adjust the setting '<u>Key for launch of the cron.php script</u>' field in the [[X-Cart:General_Options#Miscellaneous | '<u>General Settings/General options</u>']] section.
+
The first method - launching the script from the command line - enables you to exactly set the time when the script needs to be launched.  
  
If you decide to set up X-Cart to launch <u>cron.php</u> automatically, you will need to adjust the setting '<u>Run the script that launches execution of periodic tasks once per N user sessions</u>' in the [[X-Cart:General_Options#Miscellaneous | '<u>General Settings/General options</u>']] section.
+
The second method relies on X-Cart's session mechanism. It enables you to specify the frequency of <u>cron.php</u> execution in connection with X-Cart user sessions: the script will be launched once per a predetermined number of user sessions; you get to set the number of sessions.
  
<u>Example</u> of command line to launch the <u>cron.php</u> script:
+
If you decide to configure X-Cart to launch <u>cron.php</u> automatically in connection with user sessions, you will only need to adjust the setting '<u>Run the script that launches execution of periodic tasks once per N user sessions</u>' in the [[X-Cart:General_Options#Miscellaneous | '<u>General Settings/General options</u>']] 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 <u>cron.php</u>. This can be done using the setting '<u>Key for launch of the cron.php script</u>' in the [[X-Cart:General_Options#Miscellaneous | '<u>General Settings/General options</u>']] section of X-Cart Admin.
 +
:* Keep the field '<u>Run the script that launches execution of periodic tasks once per N user sessions</u>' in the [[X-Cart:General_Options#Miscellaneous | '<u>General Settings/General options</u>']] section set to the default value of "0" (zero). This tells X-Cart that you do not wish to use its sessions mechanism to determine when to run <u>cron.php</u>.
 +
:* Run the script <u>cron.php</u> from the command line (for example, via crontab) no more than once every 30 minutes.
 +
 
 +
<u>Here's an example</u> of a command to launch <u>cron.php</u>:
  
 
<pre>
 
<pre>
Line 20: Line 29:
 
</pre>
 
</pre>
  
{{Note1|'''Note:''' 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.}}
+
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.
 +
 
 +
 
 +
{{Note1|'''Important:''' We strongly recommend launching <u>cron.php</u> from the command line over allowing X-Cart to launch it in connection with user sessions. A launch of <u>cron.php</u> 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==
 
==See also==

Latest revision as of 19:31, 22 February 2018

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

The tasks include:

  • Checking whether an authorization has expired for any payment transactions in Pre-authorized status and setting the status of the respective orders to Declined.
  • Checking whether an authorization is going to expire for any payment transactions in Pre-authorized status and sending email notifications thereof to the store's Orders department. See more info on the setting "Number of days in advance that you want a reminder to be sent..." here.
  • Sending out survey invitations (X-Survey).
  • Sending out abandoned cart reminder notifications (Abandoned Cart Reminder in automated mode).

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

  • Run cron.php from the command line (For example, use system cron to launch cron.php via crontab).
  • Configure X-Cart to launch cron.php automatically.

The first method - launching the script from the command line - 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 get to set the number of sessions.

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 to use its sessions mechanism to determine when to run cron.php.
  • 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