Asterisk + AGI + PHP

I had installed Asterisk in a remote server. I need to fetch some data from the Asterisk server using PHP. So i thought to go for PHPAGI.

But how can i connect remote asterisk from my local PHP script using this PHPAGI or the common AGI . Is there any other better way to get it connected.

Please suggest !!!

It sounds like you want to connect via the asterisk manager interface and use the API/AMI to fetch data from asterisk. This is a telnet connection to the asterisk server over port 5038. This must first be setup in asterisk in the manager.conf file… asterisk AGI is used when the asterisk system initializes es the script (for example on a call, in the dialplan it executes your php)

to use the phpagi manager code first include the lib in a file via

include_once("phpagi/phpagi-asmanager.php");

then you want to create a connection and issue a command and read the response… something similar to

/*
 * Function: 	transferCall 
 * Parameters: 	string $channel, string $context, string $exten, string $priority 
 * Definition:	Connects to the pre-configured asterisk
 * 				server and attempts to transfer/redirect the
 * 				channel via a Redirect Action through the 
 * 				asterisk AMI. 
 */
function transferCall($channel,$context,$exten,$priority) {

	$asm = new AGI_AsteriskManager();
	if ($asm->connect($asterisk['host'], $asterisk['user'], $asterisk['pass'])) {
		$param["Channel"] = $channel;
		$param["Context"] = $context;
		$param["Exten"] = $exten;
		$param["Priority"] = ($priority) ? $priority : 1; 
		$res = $asm->send_request("Redirect", $param);
		if ($res['Response'] != "Success") {
			echo 'Failed to Redirect Call...';
		} else {
			echo 'Sucessfully transfered call';
		}
                $returnMsg = $res['Message'];

		$asm->disconnect();
	}
}

Obviously you would replace the send request with the AMI command that you wish to execute. along with your own parameters…

is this a correct function call :

yeah it looks correct… assuming you have the channel, context and extension setup. Also you dont HAVE to use the transferCall function… that was just an example of how to use the phpagi-manager lib…

take a look at:
http://www.voip-info.org/wiki/index.php?page=Asterisk+Manager+API+Action+Redirect

And you can also test out the correct values/syntax first by telneting into the AMI interface and attempting to do it by hand.

see: http://www.voip-info.org/wiki/view/Asterisk+manager+API