Last Modified: 05.04.2022
Attention! Provided settings are listed outside the scope of the Virtual Appliance menu. This means that the details below are provided for informational purposes only and should be used with clear understanding of your actions and under your own liability. Bitrix24 technical support reviews the questions related to Virtual Appliance menu items only.
Moving agent to cron
In large or medium-sized projects, sometimes there is an issue with the transfer of especially heavy agents to Cron.
- First, fully disable execution of agents on a hit. To do this, the command /bitrix/admin/php_command_line.php?lang=en should be executed in PHP-console of Bitrxi24 product administrative menu:
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");
As the result, we should have
- Remove the definition of the following constants from the
if(!(defined("CHK_EVENT") && CHK_EVENT===true))
- Next, create agent verification and system messages multicasts file
$_SERVER["DOCUMENT_ROOT"] = realpath(dirname(__FILE__)."/../..");
$DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"];
- And add this script into Cron:
*/5 * * * * /usr/bin/php -f /home/bitrix/www/bitrix/php_interface/cron_events.php
After that, all agents and forwarding of system Messages will be processed under cron, once each 1 minute.
: Cron failing to execute after the command means you have errors in your project. These errors, most likely, are not agent-related. Look for them in the PHP logs. You can enable an extended error display in .settings.php
Email message queue
The parameter responsible for the quantity of e-mail messages, processed at once, must modified to prevent a large of e-mail messages queue. To do that, execute the following command in PHP-console:
COption::SetOptionString("main", "mail_event_bulk", "20");
echo COption::GetOptionString("main", "mail_event_bulk", "5");
When a regular cron_events.php was launched before completing previously triggered script, agents will fail to launch and script terminates (due to agents being blocked during execution time). In this case, processing is no different from processing on a hit; a new hit can occur at the moment, when agents failed to execute on the previous hit.
Usually, scripts, executed under cron do not have limits on execution time. However, using database-handling methods in scripts can encounter an error with executing embedded scripts. To avoid this error, you can modify the value in
// when script is executed by cron, database connection limit is: 600 seconds, otherwise - 60
@set_time_limit(php_sapi_name() == "cli" ? 600 : 60);