<div>List,</div>
<div> </div>
<div>I finally decided to break down & start playing with AGI scripts, but for the life of me, I can't figure out what I am doing wrong.</div>
<div> </div>
<div>Below is a super simple script to run a query in mysql to see how many call records there are for the extension calling in, then print the total in the CLI.</div>
<div> </div>
<div>This is all I get on the CLI:</div>
<div> -- Executing AGI("SIP/216-0baa", "test.php") in new stack<br> -- Launched AGI Script /var/lib/asterisk/agi-bin/test.php<br> -- AGI Script test.php completed, returning 0<br> -- Executing Hangup("SIP/216-0baa", "") in new stack
<br> </div>
<div> </div>
<div>Here is the script:<br>#!/usr/bin/php -q<br><?php<br>ob_implicit_flush(false);<br>set_time_limit(6);<br>$stdin = fopen("php://stdin","r");<br>$stdout = fopen('php://stdout', 'w');</div>
<div>
<p>function read() {<br> global $stdin, $debug;<br> $input = str_replace("\n", "", fgets($stdin, 4096));<br> return $input;<br>}<br>function connect_db() {<br>$database="asteriskcdrdb";<br>
include("./common.php");<br> include("./dbconnect.php");<br> }</p>
<p>// parse agi headers into array<br>while ($env=read()) {<br> $env = str_replace("\"","",$env);<br> $s = split(": ",$env);<br> $agi[str_replace("agi_","",$s[0])] = trim($s[1]);
<br> if (($env == "") || ($env == "\n")) {<br> break;<br> }<br>}</p>
<p>// main program<br>$clid = $agi[callerid];<br>connect_db();</p>
<p>$query1 = "SELECT * FROM cdr WHERE dst = '$clid' ";<br>$query_result1 = @mysql_query($query1);<br>$row_count = mysql_num_rows($query_result1);<br>$row1 = @mysql_fetch_array ($query_result1);</p>
<p>fputs($stdout,"There have been\n");<br>fputs($stdout,"$row_count calls made\n");</p>
<p>fflush($stdout);<br>fclose($stdin); <br>fclose($stdout);<br>exit;<br>?></p>
<p>There are no debug errors and the query is going through just fine... and yes, I chmod 755. <br>Does anyone have a clue what I am doing wrong?</p>
<p>Thanks,</p>
<p>bp</p></div>