Ideas ??
Just updating and waiting for some help …
Dude, that’s about the best I could do for you. If this doesn’t work you have either a configuration issue or there’s something wrong with your application logic.
#!/usr/bin/php -q
<?php
set_time_limit(60);
//Array associando os Ids obtidos pelo banco de dados com os Ips das maquinas
//IP Vanessa
$agent[52]='192.168.2.26';
//IP Leticia
$agent[53]='192.168.2.55';
//IP Aline
$agent[54]='192.168.2.28';
//IP Raquel
$agent[55]='192.168.2.24';
//IP Bianca
$agent[56]='192.168.2.22';
//IP Deise
$agent[58]='192.168.2.21';
require_once('lib/phpagi.php');
// Setup initial parameters
$exten = $argv[1];
$id = $argv[2];
$agi = new AGI(); // AGI handler
// Connect to database
$dbh = mysql_connect('127.0.0.1', 'root', 'password');
mysql_select_db('qstats', $dbh) or die (mysql_error() . "\n");
$query = 'SELECT `qagent` FROM `queue_stats` WHERE `uniqueid`="' . mysql_real_escape_string($id) . '" AND `qevent`="4"';
// DEBUG
$agi->verbose("DEBUG >>> QUERY USED: $query", 3);
$res = mysql_query($query, $dbh);
// Fetch an associative array
$result = mysql_fetch_assoc($res);
// DEBUG
$agi->verbose("DEBUG >>> QUERY RETURNED " . mysql_num_rows($res) . " RESULTS. qagent RESULT: $result[qagent]", 3);
$qagent = $result['qagent'];
if ($ip = $agent[$qagent]) {
// DEBUG
$agi->verbose("DEBUG >>> IP ADDRESS SELECTED: $ip", 3);
// Open the network connection using netcat. socket_connect() should be lighter
$command = "/usr/bin/nc -w 1 $ip 10629";
$agi->verbose("DEBUG >>> ABOUT TO EXECUTE >>> $command <<<", 3);
$nc = popen($command, "w");
// Send the IP to the port specified
fwrite($nc, "$exten\n");
// Close the socket
pclose($nc);
} else {
$agi->verbose("DEBUG >>> UNABLE TO SELECT IP ADDRESS! TERMINATING!", 1);
}
mysql_close($dbh);
?>
Guys, I’m running this script out of the Asterisk enviorment and it works fine.
Maybe it’s a problem here:
asterisk -> agi -> database
When I write or select something from the database Asterisk may not work fine.
What’u think?