Tech junkies unite!
Shift8 PHP Asterisk Manager Library
Shift8 provides a simple mechanism over the AJAM asterisk interface. Apart from the obvious reason of providing an easy way to talk with a remote asterisk server, the main benefit of having an intermediate library between a software and an Asterisk server, is mostly that you can isolate the remote Asterisk, protecting the credentials and the entire PBX
Features
- Shift8 supports pretty much all asterisk manager commands
- Provides a Event listener mechanism, so that when an event occurs to notify a part of a system. The Event listener can also contain a filter to notify the listener for specific events only
- Provides a Debug listener to assist in the debugging of the application your are creating. (Currently containing a Dummy (stdout) and a syslog debug listener)
- Provides a Queue manager interface. Using Shift8 one could create a two part application that instead of executing a command directly to the remote asterisk, would queue the command via a Queue Processor, and another application would run, execute the commands in Queue for a specific interval, and store the results into the same Queue for the ‘frontend’ application to retrieve
- Supports a common (as much as possible) infrastructure for all results coming from the remote asterisk via Shift8_Event
- Shift8 library is properly documented and all the return values from the internal functions are created in a way to make the library SOAP discoverable.
Prerequisites
- Asterisk (with AJAM interface) Shift8 has been developed under Asterisk 1.6 but I don’t think there will be any problems with version 1.4
- PHP5
- PHP5 Curl extension (apt-get install php5-curl under debian/ubuntu)
- Optional: PHP5 Mysql extension (used by the Shift8 Queue Mysql Processor)
Installation
You must initially enable the manager interface in the asterisk by editing asterisk/manager.conf. You need to set:
enabled = yes webenabled = yes
You also need to create a manager for Shift8 to connect with:
[manager] secret=secret deny=0.0.0.0/0.0.0.0 permit=127.0.0.1/255.255.255.0 read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan write = system,call,agent,user,config,command,reporting,originate
Finally you must edit http.conf and enable it by setting ‘enable’ attibute to yes.
One could also setup bindaddr to explicitly define where the manager interface should bind to.
Todo
- This version of Shift8 is considered an early version where many events returned by the remote asterisk might not be trapped properly. I have decided to make it public to get some assistance in
- I need to populate the examples that come with Shift8
- I have started building a GUI (web frontend) based on AJAX and Shift8, but since I am lousy on graphical design, If anyone is willing to assist please drop me a line
- Expand the documentation
Changelog
- 0.1.2
- 0.1.1
- 0.1
- Fixed wrong parameter Date on Originate Action
- Added urlencode() in all variables passed to AJAM
- Removed a debug syslog message
- Corrected a bug on proxy function that would cause the request to be sent twice on the remote asterisk server
- Added support for saving and retrieving the last error message that has occurred in the communication with the remote asterisk (via setLastError()/getLastError())
- Changed queueAddInterface to support member, penalty, and paused status
- Initial release
Shift8 Downloads & API
| Print article | This entry was posted by mobius on December 18, 2009 at 16:37, and is filed under PHP, Telephony. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 8 months ago
Sir to whom it may concern;
I realized I couldn’t find your email contact anywhere, nor in the release note. I am very interested in your PHP Framework for Asterisk, its seem to have lot of potential. I am still learning more about this framework and really want to understand how exactly this framework handles the API Response from Asterisk after all the command been injected through its queue messages.
1) I got off guard confusing when I looked at the “QueueExecute.php”example on that line “$shift8->getQueuedCommandResponse()”, am I supposed to loop through code to see if I ever got response back from Asterisk?
2) Is it going to be similar to RESTful HTTP requests, where Asterisk will push for result in response?
3) Also, the document did mentioned about message in queue’s data been stored somewhere in the database, what is it?
Because I am critically interested in this framework, thus I would really like to understand how its designed and architect for PHP to really handle real-time communications with Asterisk. I shall look forward hearing back from you soon.
Thanks,
Jason
about 7 months ago
Hello Jason,
Sorry for taking so long to respond. I was away on holiday! I have moved the comment here since it is about the Shift8 library.
Well the logic behind Queue mechanism of the library is a bit abstract. The concept is rather simple. Shift8 provides a mechanism for adding commands to a queue, a mechanism for executing the commands in Queue and finally one to retrieve the result from an executed command.
One should implement a Shift8_Queue_Processor (see the abstract class here) that handles the inserts/updates/executes/retrievals from the queue data source. There is a simple MySQL implementation here
In order to handle a queued command one should handle it via the Shift8_Queue_Item. Each queue item must have a unique queue id (assigned by the Shift8_Queue_Processor) so as it can be retrieved afterwards via the getQueuedCommandResponse
I am guessing that this can be extended for the Processor to automatically retrieve all the processed non-retrieved commands. And in front you could have a RESTfull client.
Give me more information on what you would like to achieve, I could see if I can modify Shift8 to better suit you.
Cheers!
about 5 months ago
Hello there,
Can Shift8 be used as an AMI proxy? I’m writing PHP software that requires multiple users to send simultaneous requests to the asterisk manager. Can Shift8 help me with that task? If not, what would you recommend?
Thanks in advance,
Leo
about 5 months ago
Hello Leo,
You could use Shift8 to create an AMI proxy, but you need to pass the asterisk manager session id back and forth. You could use the getCookie(), setCookie() functions from Shift8 so that the connection will remain open.
You are also responsible for keeping the connection open with the AMI by ping()ing the asterisk library and then use waitEvent() to retrieve all events generated by the Asterisk
Remember to close the PHP session after saving/reading the cookie, because Sessions in PHP are locking and when you do a WaitEvent() will lock the session until that terminates. (It took me a while to figure that out. Thankfully there is Xdebug Profiler
)
about 5 months ago
Hi,
Could you give me examle how to ( if possible ) get uniqueid of call generated with originate.
Thanks
Pawel
about 4 months ago
Hi
First,
I can try to help coding small php tasks in my spare time (hope i’ll have one)
2nd, I’m using the old PHP AGI API and one of problems i experience is an occasional manger’s logging off. Is it an issue that you familiar with/was fixed? or is it my own bug?
Tnx! David R.
about 4 months ago
Hi David,
Well if you feel like contributing any part you are most welcome to do so!
As for your question, in any applications I’ve build using Shift8 I’ve never had any problems with the Manager disconnecting. Maybe it is AJAM that does a difference (since Shift8 is using AJAM). Give it a try and we could work any issues out!