Sergey
Sergey

Reputation: 81

Is it possible create php callback on ready input stram?

I have asterisk fast AGI application that loops in some scenario. Difference is that local launched AGI scripts asterisk drops if channel hangup.

In case of network AGI, if channel hangs, the agi script proceeding work and channel loops in wait of finish this script.

When channel hangs, asterisk send "HANGUP" message to stdout, but I use synchronius phpagi lib, that miss it. So my question is :

  1. How bind ready to read stdin event and call function callback ( that will detect possible hangup) ?

  2. How return data to stdin back if no hangup detection ?

Firstly I try find some easy way to resolve this

My test code looks like this

while( 5 < 6)
 {
 $data = $agi->request;
 $chan = $data['agi_channel'];
 $agi->Verbose(print_r($chan,1));
 $res = $agi->exec('Wait','5');
 $agi->Verbose('res = '.print_r($res,1));
 $res = $agi->exec('Playback',$path);
 $agi->Verbose('res = '.print_r($res,1));
 $var = 'ret.'.time();
 $res = $agi-> exec('Read',$var.','.$path.','.$max);
 $agi->Verbose('res = '.print_r($res,1));
 unset($res);
   }

Upvotes: 0

Views: 144

Answers (1)

arheops
arheops

Reputation: 15259

You can use function CHANNEL(state) query before each loop and check current state of channel.

If it not UP, then you have hanguped channel.

Also actions like Playback and Read will return -1(see internal documentation) in case of error or hangup.

You have no option for create callback if your framework is synchronius. Use async framework or threads.

If you use just AGI(not FastAGI) you also have option enable SIG_KILL handler.. FastAGI works via sockets, so no events.

Other option is read AMI events in second thread.

Upvotes: 0

Related Questions