[Asterisk-Users] phpagi

Mark Ackroyd mark.ackroyd at cencion.com
Thu Jan 19 09:49:54 MST 2006


> $dbconn = mysql_connect("127.0.0.1","vladimir","vladimir");
<snip>

kinda looks ok,  but I would seriously consider putting as much code as you
can into the dialplan rather than forking a PHP script for all the user
interaction.

For example, I use asterisk to handle loads of fax 2 email accounts. on 4
E1's. Each E1 goes to 

[incoming]
exten => _XXX.,1,Answer
exten => _XXX.,2,SetAccount(${DNID})
exten => _XXX.,3,AGI(callhandle.php)
exten => _XXX.,4,GotoIf($["${application}" = "none"]?6:5)
exten => _XXX.,5,Goto(${application},s,1)
exten => _XXX.,6,Hangup

The callhandle.php script looks in a database for the number that's being
called and sets variables like application, email address (and speed <--
that's still buggy at the moment)

I set up further "applications" or contexts to handle the calls

[unknownnumber]
exten => s,1,Playback(unknownnumber)
exten => s,2,Hangup

[fax2email]
exten => s,1,SetAccount(${DNID})
exten => s,n,Wait(2)
exten => s,n,Wait(2)
exten => s,n,Wait(2)
exten => s,n,Wait(2)
exten => s,n,Wait(2)
exten => s,n,Hangup

exten => fax,1,Set(FAXFILE=/var/lib/asterisk/fax/${UNIQUEID}.tif|${SPEED})
exten => fax,2,rxfax(${FAXFILE})
exten => fax,3,Hangup
exten => h,1,System(/var/lib/asterisk/agi-bin/email.php ${EMAIL} ${FAXFILE}
${RESCALE})

Now, I have only been use asterisk for about 6 months and this may not be
the best solution, but when I started I tried to get *everything* into the
PHP scripts and just use the dialplan for as little as I could. It just
didn`t work, I wasted hours on it. I guess some mistakes you just have to
learn yourself.

Some simple advice (that I have learnt) :

use the dialplan as much as possible.
develop and test your scripts outside of asterisk before using them.

bookmark http://www.voip-info.org/tiki-index.php?page=Asterisk , I refer to
it everyday.

Mark












More information about the asterisk-users mailing list