<div>Dear All,</div>
<div>&nbsp;</div>
<div>Never Mind, I have solved the problem.&nbsp; It seems that you should clear the buffer for any 'waiting' response or else you will be getting an empty '200 result=1' response.&nbsp; So be sure to read, before you write in php agi script to ensure that you will get a proper response.
</div>
<div>&nbsp;</div>
<div>Regards,</div>
<div>Kengie<br><br>&nbsp;</div>
<div><span class="gmail_quote">On 12/13/05, <b class="gmail_sendername">Kenige Ho</b> &lt;<a href="mailto:kengiepanda@gmail.com">kengiepanda@gmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Dear All,</div>
<div>&nbsp;</div>
<div>I am trying to get a variable via AGI &quot;GET VARIABLE XXXX&quot;, but using AGI DEBUG I actually do see the variable get return but somehow my retrieving the variable via php.&nbsp; I don't get the value of the variable.&nbsp; Below is my code and my results.&nbsp; Please help.&nbsp; thank you. 
</div>
<div>&nbsp;</div>
<div>Coding:</div>
<div>
<p>#!/usr/bin/php -q<br>&lt;?php<br>ob_implicit_flush(true);<br>set_time_limit(6);<br>$in = fopen(&quot;<a>php://stdin&quot;,&quot;r&quot;)</a>;<br>$stdlog = fopen(&quot;/var/log/asterisk/my_agi.log&quot;, &quot;w&quot;); 
</p>
<p>// toggle debugging output (more verbose)<br>$debug = false;</p>
<p>// Do function definitions before we start the main loop<br>function read() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; global $in, $debug;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $input = str_replace(&quot;\n&quot;, &quot;&quot;, fgets($in, 4096));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($debug) fputs($stdlog, &quot;read: $input\n&quot;); 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $input;<br>}</p>
<p>function errlog($line) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; global $err;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;VERBOSE \&quot;$line\&quot;\n&quot;;<br>}</p>
<p>function write($line) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; global $debug;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($debug) fputs($stdlog, &quot;write: $line\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $line.&quot;\n&quot;;<br>}</p>
<p>// parse agi headers into array<br>while ($env=read()) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $s = split(&quot;: &quot;,$env);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // $agivar[str_replace(&quot;agi_&quot;,&quot;&quot;,$s[0])] = trim($s[1]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // errlog($s[0].&quot;,&quot;.$s[1]); 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $agivar[$s[0]] = trim($s[1]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(($endid.phpv==&quot;&quot;) || ($env==&quot;\n&quot;)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>}</p>
<p><br>// main program<br>echo &quot;VERBOSE \&quot;fone-check\&quot;\n&quot;;<br>$tmp = &quot;GET VARIABLE xxxxx&quot;;<br>write($tmp);<br>errlog(&quot;Temp Var is &quot; . $tmp);<br>$result = read();<br>errlog(&quot;Before Strip Result is &quot; . $result); 
<br>$result = trim(ereg_replace(&quot;200 result=1&quot;,&quot;&quot;,$result));<br>$result = trim(ereg_replace(&quot;\(&quot;,&quot;&quot;,$result));<br>$result = trim(ereg_replace(&quot;\)&quot;,&quot;&quot;,$result));<br>
errlog(&quot;After Strip Result is &quot; . $result);</p>
<p>// clean up file handlers etc.<br>fclose($in);<br>fclose($stdlog);</p>
<p>exit;<br>?&gt;</p></div>
<div>Results:</div>
<div>AGI Debugging Enabled<br>AGI Tx &gt;&gt; agi_request: fone-check.agi<br>AGI Tx &gt;&gt; agi_channel: SIP/1234-adda<br>AGI Tx &gt;&gt; agi_language: en<br>AGI Tx &gt;&gt; agi_type: SIP<br>AGI Tx &gt;&gt; agi_uniqueid: 
1134460079.22<br>AGI Tx &gt;&gt; agi_callerid: 1234<br>AGI Tx &gt;&gt; agi_calleridname: 1234<br>AGI Tx &gt;&gt; agi_callingpres: 0<br>AGI Tx &gt;&gt; agi_callingani2: 0<br>AGI Tx &gt;&gt; agi_callington: 0<br>AGI Tx &gt;&gt; agi_callingtns: 0 
<br>AGI Tx &gt;&gt; agi_dnid: 1233<br>AGI Tx &gt;&gt; agi_rdnis: unknown<br>AGI Tx &gt;&gt; agi_context: test<br>AGI Tx &gt;&gt; agi_extension: 1233<br>AGI Tx &gt;&gt; agi_priority: 11<br>AGI Tx &gt;&gt; agi_enhanced: 0.0
 <br>AGI Tx &gt;&gt; agi_accountcode: test<br>AGI Tx &gt;&gt; <br>AGI Rx &lt;&lt; VERBOSE &quot;fone-check&quot;<br>&nbsp; fone-check.agi: fone-check<br>AGI Tx &gt;&gt; 200 result=1<br>AGI Rx &lt;&lt; GET VARIABLE fone<br>AGI Tx &gt;&gt; 200 result=1 (555555) 
<br>AGI Rx &lt;&lt; VERBOSE &quot;Temp Var is GET VARIABLE fone&quot;<br>&nbsp; fone-check.agi: Temp Var is GET VARIABLE fone<br>AGI Tx &gt;&gt; 200 result=1<br>AGI Rx &lt;&lt; VERBOSE &quot;Before Strip Result is 200 result=1&quot; 
<br>&nbsp; fone-check.agi: Before Strip Result is 200 result=1<br>AGI Tx &gt;&gt; 200 result=1<br>AGI Rx &lt;&lt; VERBOSE &quot;After Strip Result is &quot;<br>&nbsp; fone-check.agi: After Strip Result is <br>AGI Tx &gt;&gt; 200 result=1 
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Regards,</div>
<div>Kengie</div></blockquote></div><br>