please help, don’t know if it’s a bug, a version problem or…
tried several php and running them from console they run without problem, when i do it from agi they don’t do anything, last i’ve tried
#!/usr/bin/php
<?php require('phpagi.php'); error_reporting(E_ALL); ob_implicit_flush(true); set_time_limit(6); $stdout = fopen('php://stdout', 'w'); $in = fopen("php://stdin","r"); $stdlog = fopen("/var/log/asterisk/grabaciondatos.log", "a"); $debug = true; //$debug = false; $agi = new AGI(); function read() { global $in, $debug, $stdlog; $input = str_replace("\n", "", fgets($in, 4096)); if ($debug) fputs($stdlog, "read: $input\n"); return $input; } function errlog($line) { global $err; echo "VERBOSE \"$line\"\n"; } function write($line) { global $debug, $stdlog; if ($debug) fputs($stdlog, "write: $line\n"); echo $line."\n"; } while (!feof($in)) { $temp = fgets($in); $temp = str_replace("\n","",$temp); $s = explode(":",$temp); $agivar[$s[0]] = trim($s[1]); if (($temp == "") || ($temp == "\n")) { break; } } $para1 = $_SERVER["argv"][1]; $db = 'xx'; $dbuser = 'xx'; $dbpass = 'xx'; $dbhost = 'xxx.xxx.xxx.xxx'; $link = mysql_connect($dbhost, $dbuser, $dbpass) or die("Data base connection failed"); mysql_select_db($db) or die("data base open failed"); //$query ="select CodTelefono from telefonos where Numero='$para1'"; $query ="insert into grupos(Descripcion) values ($para1)"; $result = mysql_query($query) or die("Fallo la consulta"); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { // echo "VERBOSE \"$row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7], $row[8], $row[9]\" 2\n"; $var0 = $row[0]; } //echo "VERBOSE \"Devuelvo: variables\" 2\n"; //echo "SET VARIABLE \VAR0 \"$var0\"\n"; echo "SET VARIABLE \VAR0 \-2\n"; echo "SET VARIABLE CodNombre=-2\n"; write("SET(CodLlamada)=-2"); //echo "EXEC SET VARIABLE VAR0 ".$var0; //$agi->set_variable("VAR0", "-2"); //$agi->verbose($VAR0[data]); //$agi->exec("SET VARIABLE VAR0 $var0"); //exit(); ?>if i run
[root@elastix agi-bin]# php grabaciondatos.agi 1300
after a couple of enter keys got the row inserted (don’t know why doesn’t run all straight to the end without hitting enter key)
but if i run it from asterisk
exten => 5900,1,Answer()
exten => 5900,n,Agi(grabaciondatos.agi|1300)
exten => 5900,n,Hungup()
– Executing [5900@Grabacion:1] Answer(“SIP/1300-b7c2dcf0”, “”) in new stack
– Executing [5900@Grabacion:2] AGI(“SIP/1300-b7c2dcf0”, “grabaciondatos.agi|1300”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/grabaciondatos.agi
AGI Tx >> agi_request: grabaciondatos.agi
AGI Tx >> agi_channel: SIP/1300-b7c2dcf0
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1319328373.7
AGI Tx >> agi_callerid: 1300
AGI Tx >> agi_calleridname: device
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 5900
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: Grabacion
AGI Tx >> agi_extension: 5900
AGI Tx >> agi_priority: 2
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >> I>
– AGI Script grabaciondatos.agi completed, returning 0
== Spawn extension (Grabacion, 5900, 3) exited non-zero on 'SIP/1300-b7c2dcf0’
and nothing happens, no matter what the php says, insert, select or just set a variable
versions are just in case
Connected to Asterisk 1.4.26.1 currently running on elastix
PHP 5.1.6 (cli) (built: Nov 29 2010 16:47:37)
Copyright © 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright © 1998-2006 Zend Technologies
thanks a lot, i already spend 2 days changing phps and trying to figure it out