A very simple PHPAGI example

haamed

Joined
Jul 23, 2007
Messages
251
Likes
0
Points
0
#1
You should make and place PHP file in /var/lib/asterisk/agi-bin/testphp.php directory.
Don't forget to grant execution rights to your script


Code:
1. #!/usr/bin/php -q
2. <?
3. set_time_limit(30);
4. require('include/phpagi.php');
5. error_reporting(E_ALL);
6.
7. $agi = new AGI();
8.
9. $agi->answer();
10.
11. $agi->stream_file("demo-congrats","#");
12. do
13. {
14. $agi->stream_file("enter-some-digits","#");
15. $result = $agi->get_data('beep', 3000, 20);
16. $keys = $result['result'];
17. $agi->stream_file("you-entered","#");
18. $agi->say_digits($keys);
19. } while($keys != '111');
20. $agi->hangup();
21. ?>

after this you need an extension to call phpagi, place this code in etc/asterisk/extension_custom.conf,

Code:
[from-internal-custom]
include => testphp


[testphp]
exten => 6565,1,Answer 
exten => 6565,2,AGI(testphp.php) 
exten => 6565,3,Hangup
reload astrisk with #asterisk -rx "reload"

Now call 6565
 

bono056

Joined
Jan 19, 2010
Messages
70
Likes
0
Points
0
#2
hi
what about connecting to a external database? do you recommend using another class for running queries & after getting values from database using phpagi to read them?
 

haamed

Joined
Jul 23, 2007
Messages
251
Likes
0
Points
0
#3
In your PHP program you can do any thing you want !
You can work with any DB and have data transfer,
it is prevalent !
 

jameswilson

Joined
May 10, 2010
Messages
4
Likes
0
Points
0
#4
Many thanks for this code. I have followed the instructions. However whenever i connect to the extension from the ivr the system hangsup.
DO i need additional text to speech modules etc. Or should this work on an out of the box elastix?

James
 

haamed

Joined
Jul 23, 2007
Messages
251
Likes
0
Points
0
#5
Yes. it will work on any Asterisk System that have PHP-AGI like Trixbox and Asterisk Now.
You can use println() to found out, is it run or not, if yes in witch code line you got error.
 

riz

Joined
Aug 15, 2010
Messages
2
Likes
0
Points
0
#6
what is that script for..?? im sorry im a newbie in phpagi..
 

mikeosake

Joined
Oct 27, 2011
Messages
2
Likes
0
Points
0
#7
Hi

Very nice script.

How can i get the call duration from that script?

Michael
 

elastix809

Joined
Apr 5, 2011
Messages
85
Likes
0
Points
0
#8
i was getting this error message Exec format error, and assigned the proper permision to the file, but solved was a problem in the php path
 

mauroreggio

Joined
May 18, 2010
Messages
9
Likes
0
Points
0
#9
For Elastix 2.2.0 works, but you must pay attention at 2 "mistake":

The file to be edit for add the new extension number is /etc/asterisk/extensions_custom.conf (extensionS with an S in the end)

In the example, at the start, the php script call a required class, the path is not correct.
Change
require('include/phpagi.php');
with
require('phpagi.php');
now the php script can find the class in the correct path and not go in error, so the call not hangup.

However, thanks a lot haamed for start me in PHP-AGI ... now i can play a little :)
 

Staff online

Members online

Latest posts

Forum statistics

Threads
30,913
Messages
130,917
Members
17,589
Latest member
cristian.saiz
Top