HOW TO create and test Cron Job procedure for your website?

Discuss everything related to ApPHP Durecty CMF. All versions. Any questions related to the Directy CMF developing or using should be posted to this forum.

Moderators: alexandrleonenko, alexmst

Site Admin
Site Admin
Posts: 6169
Joined: Jan 7th, '09, 23:18

HOW TO create and test Cron Job procedure for your website?

Postby administrator » Dec 21st, '19, 13:35

The Cron Job feature is already exist in the script.
To change settings or write your own procedure, following the instructions below:

1. Settings.
Change settings according to your needs. To do this, go to General -> Site Settings -> Cron Jobs.
On this page you may change settings of running Cron Jobs.
Remember, that you may run it remotely (Batch - using your server to call cron procedure) or simultaneously
(Non-batch - when cron procedure is called every time some visit your site)

Example of Batch Cron job command:

Code: Select all

 php $HOME/public_html/cron.php >/dev/null 2>&1


Code: Select all

 cd /home/username/public_html; /usr/local/php55/bin/php /home/username/public_html/demo/cron.php

As a result you will get something like this:
cron.png (4.5 KiB) Viewed 1628 times

To block remote access to cron.php, in the server's .htaccess file or vhost configuration file add this section:

Code: Select all

<Files "cron.php">
   Order Deny,Allow
   Deny from all
   Allow from localhost
   Allow from
   Allow from xx.xx.xx.xx <-- add here your IP address (allowed)

Another way to manage remote access to the Cron Controller you may specify in _accessRules() method of this class special access permissions for different IP addresses.

Code: Select all

protected function _accessRules()
   return array(
         'actions' => array('run'),
         'ips' => array('') /* add here your IP address (allowed) */
         //'actions' => array('*'),
         //'ips' => array('', '')

Remember: Setup of your cron command is depending on your server and hosting settings.
Here the instructions for CPanel: cPanel Cron Jobs Tutorial

2. Add your own cron procedure.
To add your own procedure in cron, create special cron method in the main model of your module (the model that has the same name with your module code, ex.: Cms -> Cms->cron()).
Now may write your own code in this method.

Code: Select all

class Auctions extends CActiveRecord
    public static function cron()
     //... your cron code is here

3. Test your procedure.
After cron procedure was added, simply test it by running you site.

Return to “ApPHP Directy CMF {developers/users}”