Hi I am currently developing a IVR application using PHP/AGI. I am using the PHPAGI class at http://phpagi.sourceforge.net/ to handle the commuication with my *. The application basically asks a caller to enter in some information which is then processed and a answer is read back out to them. I want the application to loop back to the beginning after giving the answer so they can try another query. When they have finished they enter 00# and the application ends and * hangs up the call. All of this works fine. The problem is as follows. If the caller hangs up at any time during the application the following happens. 1. Asterisk console reports the call hung up. As follows == Spawn extension (default, 502, 3) exited non-zero on 'SIP/3753684-fabd' 2. However when I look in the server process list the PHP app is still running. ps -ax ... 8029 ? S 0:00 /usr/bin/php -q /usr/share/asterisk/agi-bin/test.php They only way to get rid of it is to killall -9 it. Any ideas how I can get asterisk to kill the script if the caller hangs up? Regards Jon Farmer ___________________________________________________________ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
Hello Did you tried a deadagi in place of agi A++> -----Message d'origine----- > De : asterisk-users-bounces@lists.digium.com > [mailto:asterisk-users-bounces@lists.digium.com] De la part > de Jon Farmer > Envoy? : mercredi 25 mai 2005 11:40 > ? : asterisk-users@lists.digium.com > Objet : [Asterisk-Users] PHP/AGI Problem > > The problem is as follows. If the caller hangs up at any time > during the application the following happens. > > 1. Asterisk console reports the call hung up. As follows > > == Spawn extension (default, 502, 3) exited non-zero on > 'SIP/3753684-fabd' > > 2. However when I look in the server process list the PHP app > is still running. > > ps -ax > ... > 8029 ? S 0:00 /usr/bin/php -q > /usr/share/asterisk/agi-bin/test.php > > They only way to get rid of it is to killall -9 it. >
--- Thierry Wehr <wehr@japet.com> wrote:> Hello > > Did you tried a deadagi in place of agi > > A++ > >I am calling the PHP app via deadagi. I believe what might be happening is that the application is going into a internal loop waiting for DTMF to know what to do next. I am going to investigate if I very time I poll for DTMF I check the channel status and exit() the script if the line is anything but UP. Regards Jon Jon Farmer Skype: viperdude_uk ___________________________________________________________ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
> -----Original Message----- > From: Jon Farmer [mailto:viperdude_uk@yahoo.co.uk] > Sent: 25 May 2005 11:14 > To: wehr@japet.com; Asterisk Users Mailing List - > Non-Commercial Discussion > Subject: RE: [Asterisk-Users] PHP/AGI Problem > > > > --- Thierry Wehr <wehr@japet.com> wrote: > > Hello > > > > Did you tried a deadagi in place of agi > > > > A++ > > > > > > I am calling the PHP app via deadagi. I believe what > might be happening is that the application is going > into a internal loop waiting for DTMF to know what to > do next. I am going to investigate if I very time I > poll for DTMF I check the channel status and exit() > the script if the line is anything but UP. >Although this isnt a substitute for a correctly terminating script, I would have thought that the PHP 'maximum script execution time' variable would kick-in and kill the script eventually. Maybe try setting the execution time to something quite low to test. Might work if you don't get any joy elsewhere. alex Information contained in this e-mail and any attachments are intended for the use of the addressee only, and may contain confidential information of Ubiquity Software Corporation. All unauthorized use, disclosure or distribution is strictly prohibited. If you are not the addressee, please notify the sender immediately and destroy all copies of this email. Unless otherwise expressly agreed in writing signed by an officer of Ubiquity Software Corporation, nothing in this communication shall be deemed to be legally binding. Thank you.
--- Alex Barnes <abarnes@ubiquitysoftware.com> wrote:> Although this isnt a substitute for a correctly > terminating script, > I would have thought that the PHP 'maximum script > execution time' > variable would kick-in > and kill the script eventually.Well I have already tried that I have the first line of the script saying set_time_limit(30); but it doesn't terminate the script. I have also tested detecting the channel_status and that doesn't seem to work either. This leads me to believe that the script is not running anymore but just held in limbo doing nothing except taking up resource. I would imagine that the scenario where the caller hangs up before the end of a AGI script is common so am I missing something or is the behaviour of my script normal? Regards Jon ___________________________________________________________ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
> -----Original Message----- > From: Jon Farmer [mailto:viperdude_uk@yahoo.co.uk] > Sent: 25 May 2005 14:09 > To: Asterisk Users Mailing List - Non-Commercial Discussion > Subject: RE: [Asterisk-Users] PHP/AGI Problem > > I have also tested detecting the channel_status and > that doesn't seem to work either. > > This leads me to believe that the script is not > running anymore but just held in limbo doing nothing > except taking up resource. I would imagine that the > scenario where the caller hangs up before the end of a > AGI script is common so am I missing something or is > the behaviour of my script normal? >Noticed this in the PHP docs: "Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, etc. is not included when determining the maximum time that the script has been running." I suspect that the problem is because of the script getting stuck in a state that the max_execution_time doesn't count towards. I am guessing this is because asterisk holds the connection open to AGI forever and relies on the AGI script to end of its own accord. This isnt necessarily a bad thing as you may wish to keep processing a script after a caller has hung up. I think all you can do is add some timeout mechanism to the "waiting for more dtmf" part and exit the script after so many seconds/minutes of no DTMF. HTH alex Information contained in this e-mail and any attachments are intended for the use of the addressee only, and may contain confidential information of Ubiquity Software Corporation. All unauthorized use, disclosure or distribution is strictly prohibited. If you are not the addressee, please notify the sender immediately and destroy all copies of this email. Unless otherwise expressly agreed in writing signed by an officer of Ubiquity Software Corporation, nothing in this communication shall be deemed to be legally binding. Thank you.
> Well, that is your problem. Don't use deadagi. > DeadAGI is for use if you > want to continue processing "after" the call hangs > up. That is why your > scripts are continuing to run. Use regular AGI.I get the same behaviour if I use deadagi or just agi Regards Jon ___________________________________________________________ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
--- Jay Milk <jay@skimmilk.net> wrote:> Why are you using DeadAGI? Use AGI or EAGI instead, > unless you actually > want to run on a dead-channel.I used DeadAGI just to see if it had any different behaviour in relation to my proplem. I get the same results with DeadAGI EAGI and AGI. Regards Jon Jon Farmer Skype: viperdude_uk ___________________________________________________________ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
what version of asterisk you are using? i had some problems with agi until i upgrade to asterisk 1.0.7 if you run simple agi scripts works? try using this 2, one is php, the other one is C, that will tell us if the problem is the script you are using, php, or AGI itself... #!/usr/bin/php -q <?php while(1) { $str = fread(STDIN, 80); if ( $str == "\n" ) { break; } } fwrite(STDOUT,"SAY NUMBER 19 \"\"\n"); fread(STDIN, 80); fwrite(STDOUT,"SAY NUMBER 82 \"\"\n"); fread(STDIN, 80); die(); ?> #include <stdio.h> main() { char line[80]; setlinebuf(stdout); setlinebuf(stderr); while (1) { fgets(line,80,stdin); if ( strlen(line) <= 1 ) { break; } } printf("SAY NUMBER 55 \"\"\n"); fgets(line,80,stdin); printf("SAY NUMBER 66 \"\"\n"); fgets(line,80,stdin); } On 5/25/05, Jon Farmer <viperdude_uk@yahoo.co.uk> wrote:> > --- Jay Milk <jay@skimmilk.net> wrote: > > Why are you using DeadAGI? Use AGI or EAGI instead, > > unless you actually > > want to run on a dead-channel. > > I used DeadAGI just to see if it had any different > behaviour in relation to my proplem. I get the same > results with DeadAGI EAGI and AGI. > > Regards > > Jon > > > Jon Farmer > Skype: viperdude_uk > > > > > > ___________________________________________________________ > Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com > _______________________________________________ > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >-- "Su nombre es GNU/Linux, no solamente Linux, mas info en http://www.gnu.org"
I am having the same problem even with the example script with the phpagi version 2. When I use the dtmf.php, the script keeps running if the user hangs up in the middle. Hari On 5/25/05, Jon Farmer <viperdude_uk@yahoo.co.uk> wrote:> > --- Jay Milk <jay@skimmilk.net> wrote: > > Why are you using DeadAGI? Use AGI or EAGI instead, > > unless you actually > > want to run on a dead-channel. > > I used DeadAGI just to see if it had any different > behaviour in relation to my proplem. I get the same > results with DeadAGI EAGI and AGI. > > Regards > > Jon > > > Jon Farmer > Skype: viperdude_uk > > > > > > ___________________________________________________________ > Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com > _______________________________________________ > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >
Moises Silva wrote:>what version of asterisk you are using? i had some problems with agi >until i upgrade to asterisk 1.0.7 > > >I am also using version 1.0.7. I installed it from the Xorcom CD ISO>if you run simple agi scripts works? >try using this 2, one is php, the other one is C, that will tell us if >the problem is the script you are using, php, or AGI itself... > >OK both the PHP script and the C program worked as expected. The call connected, the numbers were read out and the * server hungup. The AGI script/program exited normally. Now when I change the program to this #include <stdio.h> main() { char line[80]; setlinebuf(stdout); setlinebuf(stderr); while (1) { fgets(line,80,stdin); if ( strlen(line) <= 1 ) { break; } } while (1) { printf("SAY NUMBER 55 \"\"\n"); fgets(line,80,stdin); printf("SAY NUMBER 66 \"\"\n"); fgets(line,80,stdin); } } The numbers are read out continuously as expected but If the caller hangs up the app does not exit. The console log say the caller hung up but the app still shows in the process list. The same happened if I changed the PHP script in the same way. I am therefore assuming that AGI expects the script to detect the caller hung up and to act accordingly. Therefore I guess my question is how do I detect the caller hungup while a AGI script is running? Regards Jon
> -----Original Message----- > From: Jon Farmer [mailto:viperdude_uk@yahoo.co.uk] > Sent: 26 May 2005 08:47 > To: Moises Silva; Asterisk Users Mailing List - > Non-Commercial Discussion > Subject: Re: [Asterisk-Users] PHP/AGI Problem > > > The numbers are read out continuously as expected but If the caller > hangs up the app does not exit. The console log say the > caller hung up > but the app still shows in the process list. The same happened if I > changed the PHP script in the same way. > > I am therefore assuming that AGI expects the script to detect > the caller > hung up and to act accordingly. Therefore I guess my question > is how do > I detect the caller hungup while a AGI script is running? > > Regards > > JonThat is what I was guessing to be the problem. Normal browser interaction is, PHP script continues to execute until one of two things happens. A) The script completes processing B) The browser kills the TCP connection to the web server / user presses stop / moves to a different page Your problem is you don't want A) to ever happen cos it's a continuous loop. And B) never happens because asterisk seems to never kill an AGI connection when user hangs-up. So worse than just taking up resources on your web server / plain PHP server you are probably taking up resources on your asterisk too. You might want to try adding in some file logging and before & after each potentially blocking line, for example the read DTMF line, print out some debug to file. I suspect you might find that the script isnt blocked its just looping happily forever. Assuming the above is true I think there could be an error in your script maybe? But I have never used phpagi() before (easier to write my own class) so this is just a guess. Currently after: $res = $agi->agi_getdtmf(1,10000,$term,$prompt=FALSE); You test for no DTMF and then simply return null. Instead you could call the other piece of code you have: $status = $agi->agi_channel_status($agi->request["agi_channel"]); $agi->conlog("Status code: " . $status["status"]); $agi->conlog("Description: " . $status["description"]); if($status["description"] != "Line is up") { exit(); } Information contained in this e-mail and any attachments are intended for the use of the addressee only, and may contain confidential information of Ubiquity Software Corporation. All unauthorized use, disclosure or distribution is strictly prohibited. If you are not the addressee, please notify the sender immediately and destroy all copies of this email. Unless otherwise expressly agreed in writing signed by an officer of Ubiquity Software Corporation, nothing in this communication shall be deemed to be legally binding. Thank you.
Alex Barnes wrote:>Currently after: > >$res = $agi->agi_getdtmf(1,10000,$term,$prompt=FALSE); > >You test for no DTMF and then simply return null. >Instead you could call the other piece of code you have: > >$status = $agi->agi_channel_status($agi->request["agi_channel"]); >$agi->conlog("Status code: " . $status["status"]); >$agi->conlog("Description: " . $status["description"]); >if($status["description"] != "Line is up") { > exit(); >} > > >Alex, You are a star! I changed that bit of code based on what you said to this function getDTMF($term, $i) { global $agi; for($x=1;$x<$i;$x++) { unset($res); $res = $agi->agi_getdtmf(1,10000,$term,$prompt=FALSE); if($res[0] == "") { $status = $agi->agi_channel_status($agi->request["agi_channel"]); //$agi->conlog("Status code: " . $status["status"]); //$agi->conlog("Description: " . $status["description"]); if($status["description"] != "Line is up") { exit(); } } $agi->conlog("Res: " . $res[0]); if($res[0] == "") { break; } if($res[0] != "") { $result1 .= $res[0]; //$agi->conlog("Result var: " . $result1); } $agi->conlog("Result var: " . $result1); $agi->conlog("Channel: " . $agi->request["agi_channel"]); $status = $agi->agi_channel_status($agi->request["agi_channel"]); $agi->conlog("Status code: " . $status["status"]); $agi->conlog("Description: " . $status["description"]); if($status["description"] != "Line is up") { exit(); } } return $result1; } Now the script loops forever while the user is connected and exits if the user hangs up. Thanks to everyone who helped me out, much appreciated. Jon ___________________________________________________________ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
On 5/26/05, Jon Farmer <viperdude_uk@yahoo.co.uk> wrote:> > Now the script loops forever while the user is connected and exits if > the user hangs up. > > Thanks to everyone who helped me out, much appreciated. >Jon, What version of PHPAGI are you using? I am starting a PHPAGI app and want to know whether to use 1.12 or 2.0CVS. Thanks, Michael
Michael Stearne wrote:>Jon, > >What version of PHPAGI are you using? I am starting a PHPAGI app and >want to know whether to use 1.12 or 2.0CVS. > > >I am using 1.12 Regards Jon ___________________________________________________________ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
Hi folks, I thought I should jump in here. There appear to be a lot of PHPAGI gurus in this thread. I am running a prepaid application with Asterisk. When authentication has to be done by DTMF everything works fine. However when the user is authenticated directly from the sip phone, the channel variables seems to disappear. PS: The situation has now reversed. SIP calls retain the proper status and PSTN calls lose their status value, always returning -1. After switching to debug mode and tracing the events this is what I see. The top 2 return the proper status code. The bottom one from the PSTN gives an undefined code. I wonder whether the problem results from the parsing of the stream by the phpagi code or it comes from * itself. The only difference between the two types is the dotted.quad.ip.address:port string in the latter and I wonder if that could be the problem The output from the CHANNEL STATUS code appears okay. Tt is when it is reprocessed again to be passed into the php variable that is when it appears to go wrong. Is it an AGI bug or phpagi bug? I am using phpagi version 1.6 and wonder if it is a known bug that has been fixed in subsequent versions. Trace from Voip Connection Firefly/Xlite AGI Tx >> 510 Invalid or unknown command AGI Rx << CHANNEL STATUS IAX2/obelix@obelix/2 AGI Tx >> 200 result=6 AGI Rx << VERBOSE "result is 6" 1 prepaid_beta.php: result is 6 AGI Tx >> 200 result=1 AGI Rx << Array AGI Tx >> 510 Invalid or unknown command AGI Rx << ( AGI Tx >> 510 Invalid or unknown command AGI Rx << [status] => 6 AGI Tx >> 510 Invalid or unknown command AGI Rx << [description] => Line is up AGI Tx >> 510 Invalid or unknown command AGI Rx << ) AGI Tx >> 510 Invalid or unknown command Trace from Xlite AGI Tx >> 510 Invalid or unknown command AGI Rx << CHANNEL STATUS SIP/obelix-c27b AGI Tx >> 200 result=6 AGI Rx << VERBOSE "result is 6" 1 prepaid_beta.php: result is 6 AGI Tx >> 200 result=1 AGI Rx << Array AGI Tx >> 510 Invalid or unknown command AGI Rx << ( AGI Tx >> 510 Invalid or unknown command AGI Rx << [status] => 6 AGI Tx >> 510 Invalid or unknown command AGI Rx << [description] => Line is up AGI Tx >> 510 Invalid or unknown command AGI Rx << ) AGI Tx >> 510 Invalid or unknown command Trace from PSTN DID AGI Tx >> 510 Invalid or unknown command AGI Rx << CHANNEL STATUS IAX2/02080438682@218.14.131.186:4569/2 AGI Tx >> 200 result=6 AGI Rx << VERBOSE "result is " 1 prepaid_beta.php: result is AGI Tx >> 200 result=1 AGI Rx << Array AGI Tx >> 510 Invalid or unknown command AGI Rx << ( AGI Tx >> 510 Invalid or unknown command AGI Rx << [status] => -1 AGI Tx >> 510 Invalid or unknown command AGI Rx << [description] => unknown AGI Tx >> 510 Invalid or unknown command AGI Rx << ) AGI Tx >> 510 Invalid or unknown command Obelix. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.