php start the cycle every n seconds (php asterisk ami)



  • There's a crypt to monitor the AMI Asterisk interface. It has several functions: get_response-data from the interface, parse_response-detection in the right word, parsetodb-data in the database. This is part of the code that listens to the interface:

    while (1) {
    $response=get_response($sock);
    $parsed=parse_response($response, "Event");
    switch ($parsed){
    case "Newchannel":$parsed_event=parse_response($response, "Exten");
                    foreach($phone_b as $v)
                    if($parsed_event==$v)
                    parsetodb($response,$columns);break;
    case "QueueCallerJoin":
    case "AgentConnect":
    case "AgentComplete":
    case "QueueCallerLeave":$parsed_event=parse_response($response, "Queue");
                    foreach($queue as $v)
                    if($parsed_event==$v)
                    parsetodb($response,$columns);break;
    case "HangupRequest":
    case "SoftHangupRequest":$parsed_event=parse_response($response, "Exten");
                    foreach($queue as $v)
                    if($parsed_event==$v)
                    parsetodb($response,$columns);break;}}
    

    The problem is, the connection closes after some time of simplicity. I need to put in the cycle a keepalive function that will send special data every 60s. How do I do that so it doesn't affect the cycle? Maybe some parallel cycle?



  • So you don't have a bicycle, I advise you to see. https://packagist.org/packages/marcelog/pami and https://packagist.org/packages/react/event-loop ♪ And I think your questions will be divorced by themselves.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2