Views: 5794 (Data available since 06.02.2017)

When working with large as well as not very large projects it is often feasible to move the execution of some especially complex agents to Cron.

  • For a start, we will fully disable the execution of hit agents. To this effect, the following command should be executed on the php console of the administrative menu of the Bitrix product /bitrix/admin/php_command_line.php?lang=en:
    COption::SetOptionString("main", "agents_use_crontab", "N"); 
    echo COption::GetOptionString("main", "agents_use_crontab", "N"); 
    COption::SetOptionString("main", "check_agents", "N"); 
    echo COption::GetOptionString("main", "check_agents", "Y");

    The result of the execution should be NN.

  • Remove from the file /bitrix/php_interface/dbconn.php the definitions of the following constants:
    define("BX_CRONTAB_SUPPORT", true);
    define("BX_CRONTAB", true);

    And add:

    if(!(defined("CHK_EVENT") && CHK_EVENT===true))
       define("BX_CRONTAB_SUPPORT", true);
  • Next, we create a file for agent testing and system message distribution /bitrix/php_intarface/cron_events.php:
    $_SERVER["DOCUMENT_ROOT"] = realpath(dirname(__FILE__)."/../..");
    define("NO_KEEP_STATISTIC", true);
    define('CHK_EVENT', true);
    define("BX_CRONTAB_SUPPORT", true);
    define("BX_CRONTAB", true);
  • And add this script to Cron:
     */5 * * * * /usr/bin/php -f /home/bitrix/www/bitrix/php_interface/cron_events.php

After that, all the agents and sending of system messages will be processed under cron every 5 minutes.

To avoid building up a queue for sending mail messages, the parameter responsible for a number of mail events processed at a time must be changed. To this effect, we have to run the following command on php console:

COption::SetOptionString("main", "mail_event_bulk", "20"); 
echo COption::GetOptionString("main", "mail_event_bulk", "5");

Courses developed by «Bitrix», Inc.