<div>Jay, </div>
<div>&nbsp;</div>
<div>I&nbsp;just tried the suggested changes... same response.</div>
<div>I tested the script via command-line &amp; it works fine.</div>
<div>&nbsp;</div>
<div>[root@redhat agi-bin]# php test.php</div>
<div>Content-type: text/html</div>
<div>X-Powered-By: PHP/4.3.9</div>
<div>&nbsp;</div>
<div>VERBOSE&quot;There have been&quot;<br>VERBOSE&quot;1 calls made&quot;<br>[root@redhat agi-bin]#</div>
<div>&nbsp;</div>
<div>The permissions are correct:</div>
<div>-rwxr-xr-x&nbsp; 1 root root&nbsp; 1004 Dec 19 23:42 test.php<br>&nbsp;</div>
<div>Any other thoughts?</div>
<div>Thanks,</div>
<div>&nbsp;</div>
<div>bp</div>
<div>&nbsp;</div>
<div><span class="gmail_quote">On 12/19/06, <b class="gmail_sendername">Jay Milk</b> &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:ast-users@skimmilk.net" target="_blank">ast-users@skimmilk.net
</a>&gt; wrote:</span> </div>
<div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Does the script run from command-line?&nbsp;&nbsp;Without taking a close look at<br>this, the include statements in the function body of connect_db look 
<br>potentially messy.<br><br>Also, any output to stdout is interpreted by asterisk as a command, so<br>those fputs statements would be a problem -- do<br>fputs($stdout,&quot;VERBOSE \&quot;There have been\&quot;\n&quot;); 
<br>fputs($stdout,&quot;VERBOSE \&quot;$row_count calls made\&quot;\n&quot;);<br><br>instead.<br><br>William Piper wrote:<br>&gt; List,<br>&gt;<br>&gt; I finally decided to break down &amp; start playing with AGI scripts, but 
<br>&gt; for the life of me, I can&#39;t figure out what I am doing wrong.<br>&gt;<br>&gt; Below is a super simple script to run a query in mysql to see how many<br>&gt; call records there are for the extension calling in, then print the 
<br>&gt; total in the CLI.<br>&gt;<br>&gt; This is all I get on the CLI:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -- Executing AGI(&quot;SIP/216-0baa&quot;, &quot;test.php&quot;) in new stack<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -- Launched AGI Script /var/lib/asterisk/agi-bin/test.php 
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -- AGI Script test.php completed, returning 0<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -- Executing Hangup(&quot;SIP/216-0baa&quot;, &quot;&quot;) in new stack<br>&gt;<br>&gt;<br>&gt; Here is the script:<br>&gt; #!/usr/bin/php -q<br>&gt; &lt;?php 
<br>&gt; ob_implicit_flush(false);<br>&gt; set_time_limit(6);<br>&gt; $stdin&nbsp;&nbsp;= fopen(&quot;php://stdin&quot;,&quot;r&quot;);<br>&gt; $stdout = fopen(&#39;php://stdout&#39;, &#39;w&#39;);<br>&gt;<br>&gt; function read() { 
<br>&gt;&nbsp;&nbsp; global $stdin, $debug;<br>&gt;&nbsp;&nbsp; $input = str_replace(&quot;\n&quot;, &quot;&quot;, fgets($stdin, 4096));<br>&gt;&nbsp;&nbsp; return $input;<br>&gt; }<br>&gt; function connect_db() {<br>&gt; $database=&quot;asteriskcdrdb&quot;; 
<br>&gt;&nbsp;&nbsp;include(&quot;./common.php&quot;);<br>&gt;&nbsp;&nbsp;include(&quot;./dbconnect.php&quot;);<br>&gt;&nbsp;&nbsp;}<br>&gt;<br>&gt; // parse agi headers into array<br>&gt; while ($env=read()) {<br>&gt;&nbsp;&nbsp; $env = str_replace(&quot;\&quot;&quot;,&quot;&quot;,$env); 
<br>&gt;&nbsp;&nbsp; $s = split(&quot;: &quot;,$env);<br>&gt;&nbsp;&nbsp; $agi[str_replace(&quot;agi_&quot;,&quot;&quot;,$s[0])] = trim($s[1]);<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (($env == &quot;&quot;) || ($env == &quot;\n&quot;)) {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&gt;&nbsp;&nbsp; } 
<br>&gt; }<br>&gt;<br>&gt; // main program<br>&gt; $clid = $agi[callerid];<br>&gt; connect_db();<br>&gt;<br>&gt; $query1 = &quot;SELECT * FROM cdr WHERE dst = &#39;$clid&#39; &quot;;<br>&gt; $query_result1 = @mysql_query($query1); 
<br>&gt; $row_count = mysql_num_rows($query_result1);<br>&gt; $row1 = @mysql_fetch_array ($query_result1);<br>&gt;<br>&gt; fputs($stdout,&quot;There have been\n&quot;);<br>&gt; fputs($stdout,&quot;$row_count calls made\n&quot;); 
<br>&gt;<br>&gt; fflush($stdout);<br>&gt; fclose($stdin);<br>&gt; fclose($stdout);<br>&gt; exit;<br>&gt; ?&gt;<br>&gt;<br>&gt; There are no debug errors and the query is going through just fine...<br>&gt; and yes, I chmod 755. 
<br>&gt; Does anyone have a clue what I am doing wrong?<br>&gt;<br>&gt; Thanks,<br>&gt;<br>_______________________________________________<br>--Bandwidth and Colocation provided by <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://easynews.com/" target="_blank">
Easynews.com </a>--<br><br>asterisk-users mailing list<br>To UNSUBSCRIBE or update options visit:<br>&nbsp;&nbsp;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.digium.com/mailman/listinfo/asterisk-users" target="_blank">
http://lists.digium.com/mailman/listinfo/asterisk-users</a><br></blockquote></div><br>