Views: 3203 (Data available since 06.02.2017)
Agents – process technique that permits you to launch arbitrary PHP functions (agents) with a preset frequency.
As each page starts loading (immediately before the event of OnPageStart), the system automatically checks if there is an agent that must be launched and, if necessary, executes it.
Time accuracy of the agent launching directly depends on the steadiness and density of the site traffic. If you need to arrange for launching any PHP functions at a definitely preset time, you have to use the standard utility cron
available from most hosting providers.
In addition, resource intensive operations should not be assigned to agents, and there is a background launch option executed by cron.
In order for an agent to be executed at a set time, it must be registered in the system using the method of CAgent::AddAgent. An agent’s registration may be deleted using the function of CAgent::RemoveAgent.
If the agent function belongs to a module, this module will be automatically connected before the execution of such an agent function. Namely, the file /bitrix/modules/module ID/include.php will be connected. In this case, you have to make sure that the agent function will be available after the connection of this file.
If an agent function does not belong to any module, it must be located in the file /bitrix/php_interface/init.php. This file is automatically connected in the prologue.
The particularity of agent function creation is that the agent function must return a PHP code as a return value of the function that will be used during the next execution of this function.
Limits of Processing Techniques
Using the processing technique, please take into account the following:
- Agents have no USER variable. To be more precise, it can be created on a hosting server, but there is no guarantee that it will be a CUser class object.
- Agents do not allow authorization using the Authorize method.
- There is no pure data SITE_ID because the agent can also be executed on the page of the administrative section.
- It is impossible to know which language it will be on multi-language sites.