<div class="gmail_quote">2009/5/27 Atlanticnynex <span dir="ltr"><<a href="mailto:atlanticnynex@gmail.com">atlanticnynex@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
(Accidentally posted this to asterisk-dev, should be here)<br>
<br>
fgets is only returning one character... either when run as an AGI or<br>
run as a test on PHP on CLI...<br>
Example, enter 3333, then fgets returns '3'.<br>
</blockquote><div><br>It's not... There are problems with the way you are handling the return data...<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Also, GET DATA seems to be returning early and the loop keeps<br>
prompting 'invalid'...</blockquote><div><br>That's happening because you are sending junk to asterisk...<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Any suggestions on how to improve my AGI class so it actually works?<br>
</blockquote><div><br>Have a look at <a href="http://www.voip-info.org/wiki/view/Asterisk+AGI+php.">http://www.voip-info.org/wiki/view/Asterisk+AGI+php.</a>..<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Thanks.<br>
<br>
[code]</blockquote><div><snip><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
while ($error_count < 5 && !$msg_result) {<br>
$result = $AGI->send_cmd("GET DATA /bswitch/menu/enter-msg-id 3000 4"); <br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
$msg_id = $result[result];</blockquote><div>Problem here, you're looking to extract the value for key result (which as it's not quoted could be interpreted as a constant) from the array $result, but, $result isn't an array<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
if ($msg_id < 1000){<br>
echo "\ndebug: msgid < 1000, invalid ($msg_id)!\n";</blockquote><div>Junk is being sent to asterisk which is responding with errors (echo sends to STDOUT too), you're only getting one line at a time of response, so, after the first time in you are not getting the results you'd expect in the GET DATA, you're getting the rest of the error messages from the junk you sent...<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<?php<br>
//AGI.class.php<br>
class AGI {<br>
public $agivars;<br>
</blockquote><div><br><snip><br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
function send_cmd($cmd){<br>
fputs(STDOUT, $cmd . " \n");<br>
fflush(STDOUT);<br>
$data = fgets(STDIN, 4096);<br>
return $data;<br>
}<br>
</blockquote></div>So, as said above, you're sending the command here, then taking the next line from asterisk and dumping it back unprocessed in any way...<br><br>When you're sending the GET DATA command, if you enter 3333, what you are getting back is...<br>
<br>'200 result=3333\n'<br><br>$result actually contains this value, however, when you set $msg_id to $result[result] what you get is the first character in $msg_id, so, in this case you get '2'...<br><br>
As this is lower than 1000 you go into the invalid number part of your code where you echo a debug message then send the command to play the invalid sound file... Sending the command to play the sound file results in a 1 line response being received, your echo command put out two invalid lines, so, what is actually received as a response this time is...<br>
<br>'510 Invalid or unknown command\n'<br><br>The next command you send is the GET DATA command to try and get a new number, however, at this point there is already data waiting in the buffer, so as soon as the data is sent, your fgets returns straight away with...<br>
<br>'510 Invalid or unknown command\n'<br><br>as a result of the second line of debug output that you sent...<br><br>$result contains this string and again, you get the first character in $msg_id, so now $msg_id equals '5', this again is lower than 1000, so you go into the invalid number part of your code and drop more junk into asterisk and continue...<br>
<br>I hope that's useful in explaining the problems you are experiencing... as I said above, check out the page on voip-info, it should be enough for you to get this fixed up nicely... One think you'll notice about the examples on there, debug output is sent to a file, that way you can record information for debugging without polluting your agi...<br>
<br>d<br>