ibexa

Path

ez publish / technical manual / 5.x / features / cronjobs / running cronjobs


Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

  • Running cronjobs

    The "runcronjobs.php" script located in the root of the eZ Publish directory takes care of processing your cronjobs in the background. This script should be executed periodically. The most common practice is to instruct the operating system (or some application) to automatically run the script at regular intervals. On UNIX/Linux systems, this can be done by making use of "cron". On Windows, the script can be run by the "Scheduled Tasks" service. The following text describe how this script can be executed.

    Important Note

    Before you start, please be aware that this script execution method is the same used on eZ Publish 4.x versions, and eZ Publish 5.0 is the last version supporting the execution of scripts using this method.

    For eZ Publish 5.1 and higher versions the legacy script execution feature should be used from Symfony console.

    Running cronjobs from the shell

    It is possible to execute the "runcronjobs.php" script manually from within a system shell:

    1.  Navigate into the ezpublish_legacy directory.
    2.  Run the script (replace "example" with the actual name of the siteaccess):
      php ezpublish/console ezpublish:legacy:script runcronjobs.php --siteaccess example group_of_tasks
      

    The "group_of_tasks" option indicates that only scripts listed in the "[CronjobPart-group_of_tasks]" section of the "cronjob.ini" configuration file (or its override) will be executed. This parameter is optional. If omitted, the list of scripts will be taken from the "[CronjobSettings]" section of the "cronjob.ini" configuration file. (Please refer to the "Configuring cronjobs" section for more information.)

    The "--siteaccess example" indicates which siteaccess configuration the script should use. If you do not specify a siteaccess when running the script, then the default siteaccess will be used.

    Debugging

    It is also possible to use the "--debug" parameter that instructs the script to display the debug output at the end of execution, e.g.:

    php ezpublish/console ezpublish:legacy:script runcronjobs.php --debug --siteaccess example group_of_tasks
    

    You can use the "-d" parameter with the "all" option to get more detailed information:

    php ezpublish/console ezpublish:legacy:script runcronjobs.php -dall --siteaccess example group_of_tasks
    

    The following options are also available: "accumulator", "debug", "error", "include", "notice", "timing", "warning". Please note when provided, they must be separated using commas. The instructions given in the following example will tell the script to display debug notices and produce a list of includes:

    php ezpublish/console ezpublish:legacy:script runcronjobs.php -dinclude,notice --siteaccess example group_of_tasks
    

    The script will not make any changes to log files by default (the ones located in the "ezpublish_legacy/var/log" directory of your eZ Publish installation). If you need this functionality, you'll have to run the script using both "--debug" and "--logfiles" parameters:

    php ezpublish/console ezpublish:legacy:script runcronjobs.php --debug --siteaccess example --logfiles group_of_tasks
    

    It can also be displayed debug output including the SQL queries executed, by using the "--sql" parameter as shown in the following example:

    php ezpublish/console ezpublish:legacy:script runcronjobs.php --debug --sql --siteaccess example group_of_tasks
    

    Please note that the "--sql" parameter still depends on "--debug" and both need to be used simultaneously in order to have SQL debug output. Without the use of the "--debug" parameter no output will be displayed at all.

    Cronjobs on UNIX/Linux

    "Cron" is the name of a utility that allows the automatic execution of tasks in the background. It is typically used for periodic system administration and maintenance tasks (for example, creating a weekly backup). A program often referred to as the "cron daemon" is running silently in the background, spending its time waiting and executing cronjobs. A "cronjob" is a script or a command that is run at specified intervals by the daemon. The cronjobs must be set up in a crontab. A crontab is a text file that contains information about the intervals and the tasks that should be executed. The crontab files are not intended to be edited directly. The following table reveals which shell commands that can be used for maintaining crontabs:

    Shell command

    Description

    crontab /var/www/ezpublish/ezpublish.cron
    

    Install a new crontab from the "ezpublish.cron" file (replace "/var/www/ezpublish" by the actual path to your eZ Publish directory).

    crontab -l
    

    Display the current crontab.

    crontab -e
    

    Edit the current crontab. The modified crontab will be installed automatically.

    crontab -r
    

    Remove the current crontab.

    The following example shows how a cronjob for eZ Publish can be set up in the crontab. It assumes that eZ Publish is located in "/var/www/ezpublish/", that the PHP command line interface program is located at "/usr/local/bin/php" and that the name of the target siteaccess is "example".

    # The path to the eZ Publish directory.
    EZPUBLISH=/var/www/ezpublish
     
    # Location of the PHP command line interface binary.
    PHPCLI=/usr/local/bin/php
     
    # Instruct cron to run the main set of cronjobs
    # at 6:35am every day
    35 6 * * * cd $EZPUBLISH && $PHPCLI php ezpublish/console ezpublish:legacy:script runcronjobs.php --quiet --siteaccess example 2>&1
     
    # Instruct cron to run the "infrequent" set of cronjobs
    # at 5:20am every Monday
    20 5 * * 1 cd $EZPUBLISH && $PHPCLI php ezpublish/console ezpublish:legacy:script runcronjobs.php infrequent --quiet --siteaccess example 2>&1
     
    # Instruct cron to run the "frequent" set of cronjobs
    # every 15 minutes
    0,15,30,45 * * * * cd $EZPUBLISH && $PHPCLI ezpublish/console ezpublish:legacy:script runcronjobs.php frequent --quiet --siteaccess example 2>&1
     
    # Instruct cron to run the "monthly" set of cronjobs
    # at 4:10am the first day of every month
    10 4 1 * * cd $EZPUBLISH && $PHPCLI ezpublish/console ezpublish:legacy:script runcronjobs.php monthly --quiet --siteaccess example 2>&1
    

    When added to the crontab, the cron daemon will run the "runcronjobs.php" script using the PHP command line interface binary at the specified time. With this configuration, the main set of cronjobs will be run at 6:35am every day. This means that all the scripts listed in the "[CronjobSettings]" section of the "cronjob.ini" configuration file (or its override) will be executed once a day.

    The "infrequent" set of cronjobs will be run at 5:20am every Monday, i.e. the scripts listed in the "[CronjobPart-infrequent]" section of "cronjob.ini" (or its override) will be executed once a week.

    The "frequent" set of cronjobs will be run every 15 minutes. Only the scripts that are listed in the "[CronjobPart-frequent]" section of "cronjob.ini" (or its override) will be executed.

    The "monthly" set of cronjobs will be run at 4:10am the first day of every month, i.e. the script(s) listed in the "[CronjobPart-monthly]" section of "cronjob.ini" (or its override) will be executed once a week.

    The "--quiet" parameter instructs the script to run in quiet/silent mode (suppressing unnecessary output). The "--siteaccess example" indicates which siteaccess configuration the script should use. The "2>&1" notation instructs the system to combine standard output and error messages into one stream.

    Scheduled tasks on Windows

    Unlike UNIX/Linux systems, Windows does not provide access to cron. Instead, Windows has its own solution called "Scheduled Tasks". A scheduled task can be set up by selecting "Scheduled Tasks" from the Control Panel. This will bring up a wizard that asks what should be executed, when and so on. It should be configured to run a batch (.bat) file at regular intervals. The batch file should navigate into the eZ Publish directory and run the "runcronjobs.php" script.

    Important note

    Before you start, please be aware that this script execution method is the same used on eZ Publish 4.x versions, and eZ Publish 5.0 is the last version supporting the execution of scripts using this method.

    Svitlana Shatokhina (14/09/2010 12:14 pm)

    Sarah Haïm-Lubczanski (04/09/2014 4:04 pm)

    Geir Arne Waaler, Ricardo Correia, Sarah Haïm-Lubczanski


    Comments

    • Parameter order with cronjobPart is executed

      There is a mistake in doc (or bug in runcronjobs.php). Instead of:

      php runcronjobs.php group_of_tasks -s example
      


      should be:

      php runcronjobs.php -s example group_of_tasks
      


      otherwise specified siteaccess will not be respected - eZp will use default one.
      • Re: Parameter order with cronjobPart is executed

        Thank you. This is now reported here: http://issues.ez.no/11054
    • crontab -e ezpublish.cron removes old cronjobs

      You should check if there are any cronjobs already insalled using crontab -e because crontab -e ezpublish.cron removes old crontab settings. To be on the save side use crontab -e and copy & paste the code from ezpublish.cron.
    • Unnecessary output from cron

      runcronjobs.php -q frequent ... does produce no output as expected
      runcronjobs.php frequent -q ... does produce output, because the option comes too late
      • Re: Unnecessary output from cron

        Hi, could you please file an issue on http://issues.ez.no ? Thank you!
    • How can I list cron jobs for all the users at once?

      I have a system hosting over 3000 users, and I was wondering how I can scan through them all for any active cron job.

      Share with me...Thanks guys!
    • Cronjobs

      I use a free service to manage my cronjobs. http://www.cronwatch.com
    • Another way to pass the parameters

      Hello.

      Is it possible to pass the prarameters to the runcronjobs.php script as ...mysite.com/runcronjobs.php?parameter1=xx&parameter2=yy

      Aparently, my ISP only suports this format for configuring cronjobs (no ssh access).

      If posible, how should this one be?:

      php runcronjobs.php -s site_admin sendmail

      Thank