Home > Archive Post, Asterisk, PHP AGI > PHP Agi – beware!

PHP Agi – beware!

Hi all,

I setup a new install of Asterisk on a Virtual Ubuntu Server this week. As expected I ran into several problems when trying to get the whole thing up and running, mostly to do with CDR. I’m using a mySQL backend to record CDR data. I obtained the asterisk-addons package and the instructions indicate to do the usual ./configure, make and make install to cleanly install the cdr_addon_mysql module which is loaded by Asterisk at startup and is used to connect and write to the MySQL DB. The build goes fine, no problems indicated along the way.

So I went and got all the sql conf files up to speed(add cdr_addon_mysql to modules.conf, set enabled to yes in cdr.conf and add a mysql module to the end of it and altered cdr_mysql.conf & res_mysql.conf to match my DB settings) but nothing happened to my CDR table. After looking at the modules loaded in Asterisk I saw that the cdr_addon_mysql.so wasn’t being loaded. Seeing that I went back to the Makefile in the asterisk-addons directory and saw that asterisk.h was missing. Looking at the Asterisk wiki I was indicated to create a symbolic link to /usr/src/asterisk so that the build could find Asterisk. I did this but the error persisted. I placed the asterisk.h in the same directory but still the same problem.

Become impatient I looked for other ways to get the mysql module installed. I added the lines deb:ftp://ftp.us.debian.org/debian unstable main and deb-src ftp://ftp.us.debian.org/debian unstable main to /etc/apt/sources.list and did an apt-get update. Now I was able to do apt-get install asterisk-mysql and the addon was automatically got and placed in my /usr/lib/asterisk/modules and loaded up at startup of Asterisk :) Still isn’t working though my settings must be wrong somewhere.

Here is what I did to install Asterisk….

 Need to get install seperately :
    apt-get install Asterisk
    apt-get install Build-essential
    apt-get instal subversion

    Setup Call Logging CDR - still not working fully
    MySQL - cmd MySQL for CDR
    apt-get instal Mysql-server
    apt-get install Mysql-devel
    Download asterisk-addons from digium svn and compile, this is whats giving me bother building is failing. Follow instructions above.

    Execute MYSQL scripts to create database tables. Grant privileges to asterisk@localhost user.

    apt-get Install PHP5-cli php5-common php5-pear php5-mysql

    Install SOX and Lame for mp3 playback and file conversions
    apt-get install sox lame mpg123

    For TTS:
    apt-get festival festvox-8k
    Change /etc/Festival.scm to match one at http://www.voip-info.org/wiki/view/Asterisk+festival+installation

    Update festival.scm to set the default to be voice_rab_diphone
    Change the .scm /usr/share/festival/voices/whatever the voice is called/festvox/voicename.scm. Search for Duration_Stretch and change this value. Restart festival and test. I used 1.4 for rab_diphone.

    Get PHPAGI.php and the other agi modules at http://phpagi.sourceforge.net/ put them in /usr/share/asterisk/bin directory
    Get Magpie RSS for podcast reader and place MagpieRSS directory in /usr/share/asterisk/bin
    Create a cache directory that is writable by Asterisk in the /usr/share/asterisk/bin directory

    Copy existing iax.conf,sip.conf, extensions.conf over to /etc/asterisk

    Also copy existing cdr.conf, jabber.conf, gtalk.conf, festival.conf, dsnmgr.conf,cdr_custom.conf,res_mysql_conf

    Need to get new sound files and put in /usr/share/asterisk/sounds
    Get php scripts and put in /var/lib/asterisk/agi-bin OR /usr/share/asterisk/bin

    Disable res_pgsql and res_odbc

Have been doing a lot of work with PHP AGI in the last week. I’ve been charged with the job of grabbing some XML from a database, parsing it and then playing back a bunch of files whilst recording user input. So looking around I saw that SimpleXML is a nice easy way of parsing XML with PHP and is built into PHP5. Sweet. So I began to go parse some of the xml using SimpleXML…below is an XML snippet like what I had:


    xyz

So I basically created the SimpleXMLElement

$theXML = new SimpleXMLElement('xyz');

Then to access the child of the root element I did this:

$child = $theXML->child;

All good so far. To see what was coming back I used the ‘verbose’ function of phpagi. As all that was being saved in the child variable was a string I was suprised to see what was being output on the Asterisk console:

SimpleElement Object
{
    [0] -> xyz
}

So I began to think an array was being saved in ‘child’ and tried accessing and outputting $child[o]. Again the verbose function output the EXACT same output for the $child[0] and $child. Confused I was going around in circles and doing lots of tutorials to see where I was going wrong but couldn’t find it, it is very simple after all its hard to get wrong!

The problem was to do with the php agi VERBOSE function which does a print_r on the passed in information. I decided to test if Asterisk would convert the ‘array’ in $child to text so I used the text2wav function to output the variable. Funny thing was it would just say ‘xyz’ which is exactly what I wanted in $child. So essentially I was troubleshooting a problem that didn’t exist all because of some funky output from the verbose function.

All in all my advice to any php agi Asterisk programmers would be : DON’T TRUST THE PHP AGI VERBOSE FUNCTION!!

Categories: Archive Post, Asterisk, PHP AGI Tags:
  1. November 20th, 2009 at 01:29 | #1

    Festival was suck and have problem also.Try use cepstral and dont use any middleware like apt swift which may make ur os crash….

  1. No trackbacks yet.