I’m very new to Asterisk and Linux, I have quite a bit of experiance developing on the windows platform, so I get most concepts just need to learn to find my way here…
I’m trying to setup PHP based AGI scripting, on a clean AsteriskNow installation.
I’ve been trying all kinds of things, amonst them installing php using some command…
By executing ‘php test.php’ in my agi-bin directory
I seem to get some restults…
but things do not seem to work the way they should yet…
Could someone point me to a walkthrough for beginners on this???
#!/usr/bin/php -q
<?php
declare(ticks = 1);
ob_implicit_flush(true);
function sig_handler($signo){
//this function is called when the caller hangs up
}
pcntl_signal(SIGHUP,"sig_handler");
//MAIN PROGRAM
?>
and save it in /var/lib/asterisk/agi-bin
don’t forget to give the permission “chmod 755”
The script is identical to the one you posted (copy-past…)
The only difference is that I call the script from the [default] context in the extensions.conf file.
But I’m quite sure that part works:
if I connect and then dail 6000, I get the conference
when I dail 6001 I get the default supplied agi-test.agi script (perl)
but when dailing 9000… nothing, just a disconnect. (and yes I did rename your file from ivr.agi to mytest.agi)
You must replace the comment //MAIN PROGRAM with php code!
Try this:
[code]#!/usr/bin/php -q
<?php
declare(ticks = 1);
ob_implicit_flush(true);
function sig_handler($signo){
//this function is called when the caller hangs up
//for example you can write into log db
}
pcntl_signal(SIGHUP,"sig_handler"); //detect caller hangs up
//dont' forget this import
require_once ('phpagi.php');
require_once ('phpagi-asmanager.php');
$agi = new AGI();
$agi->answer();
$agi->verbose("CALLER ID:" . $agi->request[agi_callerid]);
$agi->verbose("CALLED ID:" . $agi->request[agi_extension]);
$agi->exec("SAY DIGITS 12345"); //instead of this you can use another function like playback,.....
$agi->exec("WAIT 1"); //wait 1 second
$agi->hangup();
exit();
?>[/code]
So comment the line with pcntl and it must work!
You can use also another language to permorm this script, with php i realize complex ivr…
This must work:
[code]#!/usr/bin/php -q
<?php
declare(ticks = 1);
ob_implicit_flush(true);
/*
function sig_handler($signo){
//this function is called when the caller hangs up
//for example you can write into log db
}
pcntl_signal(SIGHUP,"sig_handler"); //detect caller hangs up
*/
//dont' forget this import
require_once ('phpagi.php');
require_once ('phpagi-asmanager.php');
$agi = new AGI();
$agi->answer();
$agi->verbose("CALLER ID:" . $agi->request[agi_callerid]);
$agi->verbose("CALLED ID:" . $agi->request[agi_extension]);
$agi->exec("SAY DIGITS 12345"); //instead of this you can use another function like playback,.....
$agi->exec("WAIT 1"); //wait 1 second
$agi->hangup();
exit();
?>[/code]
I’ve tried your example (also installed the pgpagi files)
I still get disconnected…
When I run the php file from the command line i get these results:
(need to press enter a lot…)
[code][root@localhost agi-bin]# php mytest.agi
PHP Warning: mime_magic: type regex BEGIN[[:space:]]*[{] application/x-awk invalid in Unknown on line 0
PHP Warning: mime_magic: type search/400 \input text/x-tex invalid in Unknown on line 0
PHP Warning: mime_magic: type search/400 \section text/x-tex invalid in Unknown on line 0
PHP Warning: mime_magic: type search/400 \setlength text/x-tex invalid in Unknown on line 0
PHP Warning: mime_magic: type search/400 \documentstyle text/x-tex invalid in Unknown on line 0
PHP Warning: mime_magic: type search/400 \chapter text/x-tex invalid in Unknown on line 0
PHP Warning: mime_magic: type search/400 \documentclass text/x-tex invalid in Unknown on line 0
<?php
ob_implicit_flush(true);
set_time_limit('1800'); //the max life in seconds of the script
//dont' forget this import
require_once ('phpagi.php');
require_once ('phpagi-asmanager.php');
$agi = new AGI();
$agi->answer();
$agi->verbose("-----------ANSWER-------------");
$agi->exec("WAIT 1"); //wait 1 second
$agi->hangup();
exit();
?>[/code]
When you are on the CLI, before call the 9000 digits agi debug and press enter. After call 9000 and you must see -----------ANSWER-------------
If doesn’t appear post me the CLI result…
UH… on the risk that I reveal myself as a compleet NOOB…
Which CLI?
I have 2 options right now:
ssh connection to my AsteriskNow installation (login as admin --> su to get root access).
I think this is the linux console. When I run agi debug here someone named bash tells me the command is not found…
the Asterisk CLI option in the AstriskNow GUI (web)
this allows me to execute commands but does not seem to return any debug info.
when I run agi debug, I see this:
That seems to get me in the right direction thanks!
There was a whitespace after the -q…
One small step ahead now…
when running:
[code]#!/usr/bin/php -q
<?php
ob_implicit_flush(true);
set_time_limit('1800'); //the max life in seconds of the script
//dont' forget this import
require_once ('phpagi.php');
require_once ('phpagi-asmanager.php');
$agi = new AGI();
$agi->answer();
$agi->exec("SAY DIGITS 12345");
$agi->verbose("-----------ANSWER-------------");
$agi->exec("WAIT 1"); //wait 1 second
$agi->hangup();
exit();
?>[/code]