There is a script to monitor the interface AMI Asterisk. It has several functions: get_response-receiving data from the interface, parse_response-searching the data of the desired word, parsetodb-record in the database. Here is the part of the code that is listening 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 that the connection is closed after some idle time. I need to insert a "keepalive" function in the loop, which will send special data every 60s. How can I do this so that it does not affect the work of the cycle? Perhaps some kind of parallel loop?

    1 answer 1

    So that you do not have a bike, I advise you to familiarize yourself with PAMI and React Event-Loop . And I think your questions will shatter by themselves.