A small fix in the phpagi code shipped with freepbx can avoid some unwanted connection timeouts.
File:
/var/www/localhost/htdocs/freepbx/admin/modules/framework/agi-bin/phpagi-asmanager.php
Within function:
function connect($server=NULL, $username=NULL, $secret=NULL)
change these lines (which modify fsockopen by adding a connection timeout and insert stream_set_timeout for read/write timeouts):
$this->socket = @fsockopen($this->server, $this->port, $errno, $errstr, 10);
if($this->socket == false)
{
$this->log("Unable to connect to manager {$this->server}:{$this->port} ($errno): $errstr");
return false;
} else
stream_set_timeout($this->socket, 2);
Add TRUE to the disconnect funcion here:
// login
$res = $this->send_request('login', array('Username'=>$username, 'Secret'=>$secret));
if($res['Response'] != 'Success')
{
$this->log("Failed to login.");
$this->disconnect(TRUE);
return false;
}
Finally, modify the disconnect function:
function disconnect($dontlogoff=NULL)
{
if (!$dontlogoff)
$this->logoff();
fclose($this->socket);
}
This is just a suggestion but these small changes actually help when there are transient AMI login problems. Some of my custom phpagi scripts went (seldom) into a 100% CPU consumption state because they hung on $this->logoff(); when fsockopen had returned TRUE.
I could discuss this on the phpagi SF bug tracker but its development seems at a stop since 2005. Also, freepbx has phpagi incorporated.