<html dir="ltr"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style title="owaParaStyle"><!--P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
--></style>
</head>
<body ocsi="x">
<p>Hi All,</p>
<p><font face="times new roman"></font> </p>
<p><font face="times new roman">I'm having problems getting results from a PHP file. This is what the CLI is showing.</font></p>
<p><font face="times new roman"></font> </p>
<p> -- Executing [111@internal:1] AGI("Console/dsp", "GoTalk.php") in new stack<br>
-- Launched AGI Script /var/lib/asterisk/agi-bin/GoTalk.php<br>
[Dec 14 11:57:25] ERROR[20260]: utils.c:1019 ast_carefulwrite: write() returned error: Broken pipe<br>
</p>
<p><font face="times new roman">If I run the PHP file from Linux it returns the result I want but how do I get that result back into Asterisk. I'm using Asterisk 1.6.0.10.</font></p>
<p><font face="times new roman"></font> </p>
<p><font face="times new roman">My extensions.conf file looks like:</font></p>
<p> </p>
<p>exten => 111,1,Answer()</p>
<p>exten => 111,n,AGI(GoTalk.php)<br>
exten => 111,n,NoOp(Result is : ${callnum})<br>
exten => 111,n,HangUp()<br>
</p>
<p><font face="times new roman"></font> </p>
<p><font face="times new roman">My php file is:</font></p>
<p><font face="times new roman">#!/usr/bin/php<br>
<?php</font></p>
<p><font face="times new roman">$start = '5';</font></p>
<p><font face="times new roman">$mysql_host = 'localhost';<br>
$mysql_user = 'username';<br>
$mysql_password = 'password';<br>
$my_database = 'asteriskcdr';<br>
$dbtable = 'cdr';</font></p>
<font face="times new roman">
<p><br>
$from_date = '20091205000000';<br>
$to_date = '20100104235959';</p>
<p>$callnum = '0';<br>
$minutes = '0';</p>
<p>$query_duration = "SELECT SUM(billsec) FROM $dbtable WHERE calldate >= $from_date AND calldate <= $to_date AND disposition='ANSWERED' AND dst like '04%'";<br>
$query_calls = "SELECT COUNT(dst) FROM $dbtable WHERE calldate >= $from_date AND calldate <= $to_date AND disposition='ANSWERED' AND dst like '04%'";<br>
$query_cb_calls = "SELECT COUNT(dst) FROM $dbtable WHERE calldate >= $from_date AND calldate <= $to_date AND disposition='ANSWERED' AND dst like '04%' AND src like '04%'";</p>
<p>// Connecting, selecting database<br>
$link = mysql_connect($mysql_host, $mysql_user, $mysql_password)<br>
or die('Could not connect: ' . mysql_error());</p>
<p>mysql_select_db($my_database) or die('Could not select database');</p>
<p>// Performing SQL query<br>
$result = mysql_query($query_calls) or die('Query failed: ' . mysql_error());</p>
<p>// Printing results in HTML<br>
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {<br>
foreach ($line as $col_value) {<br>
$callnum = $col_value;<br>
}<br>
}</p>
<p><br>
// Performing SQL query<br>
$result = mysql_query($query_cb_calls) or die('Query failed: ' . mysql_error());</p>
<p>// Printing results in HTML<br>
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {<br>
foreach ($line as $col_value) {<br>
$callnum = $callnum + $col_value; }<br>
}</p>
<p> </p>
<p>// Performing SQL query<br>
$result = mysql_query($query_duration) or die('Query failed: ' . mysql_error());</p>
<p>// Printing results in HTML<br>
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {<br>
foreach ($line as $col_value) {<br>
$minutes = round($col_value/60);<br>
}<br>
}</p>
<p><br>
// Free resultset<br>
mysql_free_result($result);</p>
<p>// Closing connection<br>
mysql_close($link);</p>
<p>echo "$callnum,$minutes";<br>
fwrite(STDOUT,"$callnum,$minutes");<br>
fflush($stdout);</p>
<p>?><br>
</font></p>
</body>
</html>