Well it’s been a while since the PHP Asterisk Manager API was released and I’ve yet to produce a clear and definitive example of its use. So here goes.
Prerequisites
Your Asterisk server must be set up correctly before this API can ’speak’ to the server.
- First you’ll need to ensure the Manager interface is active and you’ve set the correct permissions (If you’d like this explaining please leave a comment).
- Secondly make sure you are setup with the ability for two endpoints to call each other. This won’t work if you have one phone on the server.
Install
Firstly you’ll need to get hold of the library and there’s two routes to take. You can either install via PEAR or simply checkout the source from the Google Project:
svn checkout http://asterisk-php-api.googlecode.com/svn/trunk/ asterisk-php-api
Originating a Call
Once you’ve got it all ready you need to start your new file thats going to make use of it. In this example I’m creating a simple dialler called: “call.php” which will take two GET variables, with one being the callee and one the caller.
'192.168.1.5',
'port' => '5038',
'auto_connect' => true
);
//Initialise
$am = new Net_AsteriskManager($params);
//Login to the Asterisk Manager interface
$am->login('user', 'pass');
//Originate Call is one of the commands available and it causes a call to be made and connected between two endpoints.
$am->originateCall($number, $from, $context, $cid, 1, 30000);
?>
By looking at the comments above you should see how this works and the steps required. If not then leave any comments and I’ll build on the above. It’s sometimes difficult to know what people already know so apologies if this is too simple or complex.
Later on I’ll show how to work with queues – adding, removing, listing, etc.










My experience with the manager API has been that it fails during peak loads: I does not react to commands, or responses are cut off after a LF in the middle of the contents. Therefore, some type of handshake mechanism should be implemented in order to be sure that it does what you want it to do. Are such measures implemented in the PHP API?
I did look at implementing some form of mechanism to handle lockups mid-command. When the interface has stopped accepting a command or fails to fully return a response I’ve attempted to make a secondary connection and authorisation to re-issue commands.
Unfortunately this hasn’t helped. When the Manager interface stops receieving commands on the current session it seems to stop on any future session until either the server is restarted or time has passed.
As the Manager interface has a passive nature its not possible to send termination controls for the current or last sent command either.
I’ve rarely had these issues though and I suspect that if you’re getting problems like this then you could probably help the situation by looking at hardware resources or other optimisations.
Another possible solution is to use the AGI when possible. Then you’re moving the burden away from Asterisk onto an external service.
I try it your code but is not working fine i can’t established a connection to the sid: channel.c: Unable to request channel SIP/205
But when I try to made a call from x-lite it works fine.
Do you know any solution?
Best regards
Raul
Here is the same thing using Perl:
http://www.syednetworks.com/asterisk-managerconf-configuration
I am having that program installed caused a lot of crashes. Not good for me