I'm trying to use add_event_handler. I want to each event to fire off my event handler, then wait for another event.
Here is the code I'm using. I tried it with and without the while and sleep as well. Does anyone have any pointers on making this work? My background is not in OO style programming.
I'm using php from the command line for testing.
I'm trying to use add_event_handler. I want to each event to fire off my event handler, then wait for another event.
Here is the code I'm using. I tried it with and without the while and sleep as well. Does anyone have any pointers on making this work? My background is not in OO style programming.
require_once("/var/www/pbxmax-bin/phpagi-asmanager.php");
$manager = new AGI_AsteriskManager();
$result = $manager->connect();
if($result === TRUE) {
echo "Connection established.\n";
$manager->add_event_handler("*", "dump_event");
while (1 == 1) {
sleep(1);
}
} else {
echo "Connection failed.\n";
exit;
}
function dump_event($ecode,$data,$server,$port) {
echo "received event '$ecode' from $server:$port\n";
print_r($data);
}
You need to setup an eventmask to indicate what events your manager application should receive, eg:
$manager->Events("on");
Check phpagi-asmanager.php for more information.
The trick is to loop but not sleep since while sleeping you ain't receiving anything.
Just do the following