I am working a php script that I want to record all events (will work on filters later) as they occur. In my script below though, I loop for 5 seconds and then when I disconnect from astManager, but nothing is displayed until AFTER the loop finishes and it disconnects. Even my "debug" text does not display until after.
I need to get realtime (or continuous) events so I can parse them and not miss any.
How do I get my script to loop continuously/indefinitely and display the events as they occur?
NOTE: I put script in /var/www/html/ for testing purposes so I can access from my local network over VPN (it is NOT web accessible).
<?php$BASE_PATH="/var/lib/asterisk/agi-bin/";require$BASE_PATH."phpagi.php";$astManager=newAGI_AsteriskManager();$res=$astManager->connect($ast_host,$ast_user,$ast_pass);if(!$res){syslog(LOG_INFO,"Connection to Asterisk manager failed.");//echo 'Connection to Asterisk manager failed.';die(100);}echo'debug 1';$astManager->add_event_handler('*','evt_all');$start_time=date('His');$end_time=$start_time+5;//in secondsfor($x=$start_time;$x<$end_time;$x=date('His')){}//LOOP until time runs outecho'debug 2';// Now we close the connection and logout$astManager->disconnect();//FUNCTION - Do something with all eventsfunctionevt_all($ecode,$data,$server,$port){echo'<br>'.$ecode.' - '.print_r($data,1);}?>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am working a php script that I want to record all events (will work on filters later) as they occur. In my script below though, I loop for 5 seconds and then when I disconnect from astManager, but nothing is displayed until AFTER the loop finishes and it disconnects. Even my "debug" text does not display until after.
I need to get realtime (or continuous) events so I can parse them and not miss any.
How do I get my script to loop continuously/indefinitely and display the events as they occur?
NOTE: I put script in /var/www/html/ for testing purposes so I can access from my local network over VPN (it is NOT web accessible).
The trick is to loop but not sleep since while sleeping you ain't receiving anything.
Just do the following