[asterisk-users] Re: Proper AGI use with MySQL

Tony Mountifield tony at softins.clara.co.uk
Tue May 15 03:28:35 MST 2007


In article <47502.192.168.1.70.1179178812.webmail at 192.168.1.70>,
 <lists at infoway.net> wrote:
> 
> All this seems to be working. However, we just don't feel we are doing
> things properly and reading up on the wiki more about AGI and dialing
> out, etc, just makes me feel we could be doing things better.
> 
> Here are some of the things we think we could be doing better but are
> not sure:
> 
> 1) Ideally, we would like for the AGI script to know when the call hangs
> up so that it properly updates "callend" without having to run the
> DeadAGI command in the h extension.

IMHO, using DeadAGI in the 'h' extension is the correct way to do it. I use
that technique in many applications and have found it reliable. I'm not sure
why you feel it is not the "proper" way.

> 2) We would like for the AGI script to stay running for the life of the
> call and keep in memory all the user's IVR selections until the call is
> hung up. At which point, we could actually INSERT the row in MySQL with
> all the data, instead of constantly hitting the database with updates.

You then have the (hopefully rare) problem that if the script, or
asterisk, or the box goes down before you do the final insert, you have
lost all the selections. I would do the updates as they happen. MySQL is
pretty good about caching records, so multiple updates to the same record
should get optimised quite well.

> 3) We read on the wiki the following: "If the AGI application dials
> outward by executing Dial, control over the call returns to the dialplan
> and the script loses contact with the Asterisk server. The script
> continues to run in the background by itself and is free to clean up and
> do post-dial processing." In our IVR, we always exit with -1. So, this
> statement confused us. Does it mean that when we transfer the call to
> the queue, we should actually return 0 instead of -1 to indicate that
> the AGI is still running? Can anyone explain this further?

Can't comment on this one, as I never use AGI to dial. My AGIs just
set the context, extension and priority, and exit to the dialplan to do
any dialling.

> 4) When should we close the database handle? Currently, we have it at
> the end of the AGI script and also as part of the DeadAGI script.
> However, which one is actually closing it, we don't know.

An AGI is a separate process, so will need to create its own database
handle by calling mysql_connect(). For tidiness, it should release the
handle by calling mysql_close() before exiting, but if it doesn't, the
handle will be closed automatically as the process exits.

There is no way the DeadAGI script could inherit a database handle from
the original AGI acript.

Hope this helps.

Cheers
Tony
-- 
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org


More information about the asterisk-users mailing list