Nathan Alpert
2004-Jul-15 14:35 UTC
[Asterisk-Users] Important note for AGI with PHP newbies
I say this note is important only because I (a AGI PHP newbie) was tormented by this problem for many an hour, even though I'm sure it's documented somewhere or obvious to more experienced users. So as I was experimenting with AGI in PHP scripting I was baffled by why Asterisk was properly receiving AGI commands written to stdout but always returning "510 invalid command" to the stdin. For example, doing a verbose command would properly show the message in the asterisk CLI but it would return "510 invalid." Also, commands like GET DATA and GET DIGIT would not work at all, even though the CLI would report "Playing file my-file." After spending literally hours fumbling around with different buffer flushing schemes in PHP to no avail (I already knew I was doing the flushing properly anyway) and sending an email to this email list, I finally wrote a script that actually returned the proper values in stdin. The thing that fixed it was putting the "-q" argument in the "#!/usr/local/php -q" thing that you put on the first line of your script file. Apparently this argument tells PHP to supress HTML headers or something according to the documentation. I'm still not %100 sure why this would make a difference, but it does! Everybody is probably already aware of this, but I wasn't, so I hope this helps any other newbie who had the same problem. -nate alpert
Original Message----- From: asterisk-users-admin@lists.digium.com [mailto:asterisk-users-admin@lists.digium.com]On Behalf Of Nathan Alpert Sent: 15 July 2004 22:36 To: asterisk-users@lists.digium.com Subject: [Asterisk-Users] Important note for AGI with PHP newbies I say this note is important only because I (a AGI PHP newbie) was tormented by this problem for many an hour, even though I'm sure it's documented somewhere or obvious to more experienced users. So as I was experimenting with AGI in PHP scripting I was baffled by why Asterisk was properly receiving AGI commands written to stdout but always returning "510 invalid command" to the stdin. For example, doing a verbose command would properly show the message in the asterisk CLI but it would return "510 invalid." Also, commands like GET DATA and GET DIGIT would not work at all, even though the CLI would report "Playing file my-file." After spending literally hours fumbling around with different buffer flushing schemes in PHP to no avail (I already knew I was doing the flushing properly anyway) and sending an email to this email list, I finally wrote a script that actually returned the proper values in stdin. The thing that fixed it was putting the "-q" argument in the "#!/usr/local/php -q" thing that you put on the first line of your script file. Apparently this argument tells PHP to supress HTML headers or something according to the documentation. I'm still not %100 sure why this would make a difference, but it does! Everybody is probably already aware of this, but I wasn't, so I hope this helps any other newbie who had the same problem. -nate alpert I wish more people did the same. I mean share there positive experience, ideally it would be good if you can add your experience to the wiki (that's where I try to do the same). Most people (IMHO) ask questions and don't bother sharing their resolutions with others. Umar
Because php belongs on the web so it defaults to outputting html headers. bkw> -----Original Message----- > From: asterisk-users-admin@lists.digium.com [mailto:asterisk-users- > admin@lists.digium.com] On Behalf Of Nathan Alpert > Sent: Thursday, July 15, 2004 4:36 PM > To: asterisk-users@lists.digium.com > Subject: [Asterisk-Users] Important note for AGI with PHP newbies > > I say this note is important only because I (a AGI PHP newbie) was > tormented by this problem for many an hour, even though I'm sure it's > documented somewhere or obvious to more experienced users. > > So as I was experimenting with AGI in PHP scripting I was baffled by why > Asterisk was properly receiving AGI commands written to stdout but > always returning "510 invalid command" to the stdin. For example, doing > a verbose command would properly show the message in the asterisk CLI > but it would return "510 invalid." Also, commands like GET DATA and GET > DIGIT would not work at all, even though the CLI would report "Playing > file my-file." > > After spending literally hours fumbling around with different buffer > flushing schemes in PHP to no avail (I already knew I was doing the > flushing properly anyway) and sending an email to this email list, I > finally wrote a script that actually returned the proper values in > stdin. > > The thing that fixed it was putting the "-q" argument in the > "#!/usr/local/php -q" thing that you put on the first line of your > script file. Apparently this argument tells PHP to supress HTML headers > or something according to the documentation. I'm still not %100 sure why > this would make a difference, but it does! > > Everybody is probably already aware of this, but I wasn't, so I hope > this helps any other newbie who had the same problem. > > -nate alpert > > _______________________________________________ > 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
Steven Critchfield
2004-Jul-15 16:59 UTC
[Asterisk-Users] Important note for AGI with PHP newbies
On Thu, 2004-07-15 at 16:35, Nathan Alpert wrote:> I say this note is important only because I (a AGI PHP newbie) was > tormented by this problem for many an hour, even though I'm sure it's > documented somewhere or obvious to more experienced users.> The thing that fixed it was putting the "-q" argument in the > "#!/usr/local/php -q" thing that you put on the first line of your > script file. Apparently this argument tells PHP to supress HTML headers > or something according to the documentation. I'm still not %100 sure why > this would make a difference, but it does!Since the IO is buffered and your app mostlikely only expected one line of return for every one line of output. If the headers go out and say output 5 lines of headers, you would then have 5 responses to slug through before you get to your good responses. Of course you are then out of sync too. Now you have some more amunition as to why the -q is important. -- Steven Critchfield <critch@basesys.com>