phpagentbitrix

Creating Agent and Running every 60 sec. in bitrix24


I have added one function in timeman mosule as follows.

class CTimeManReport extends CAllTimeManReport
{

   function testAgent()
   {
    mail('t@demo.co.in','agent','agent');
    return "testAgent();";
   }


}

Now I want to run this function every 60 sec.I have added agent though control panel in agent section,but its running only once.


Solution

  • After running the agent bitrix added to database value that agent function returns. So in your case, it must be return "CTimeManReport::testAgent();" because your function is a class method.

    Also, it must be a class method, not an instance method, so add public static before your function

    So, try to do something like that:

    class CTimeManReport extends CAllTimeManReport
    {
    
       public static function testAgent()
       {
        mail('t@demo.co.in','agent','agent');
        return "CTimeManReport::testAgent();";
       }
    }
    

    If this advice doesn't help, you can add cron support for your agents, because by default they work on pages reloads. Follow this link for instructions

    P.S. don't add your own code into the bitrix module's code. Because you may lose your code after bitrix updates. Add your own code or include your classes into the local/php_interface/init.php