I'm making changes to an Asterisk IVR designed by someone else. The application uses both func_odbc.conf and php agi to access an external MySQL database. In the php routines, I would like to use the persistent connection that is established in the dialplan, rather than creating a new connection each time they run. How can I do this? In res_odbc.conf, the context "asterisk" is established, successfully referencing "asterisk-connector" in odbc.ini. pre-connect => yes resulting in a persistent connection at startup. Opening a connection in the php routines takes about 5 seconds, which is unacceptable. --Don -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20131203/15be8ac2/attachment.html>
Don Kelly wrote:> I?m making changes to an Asterisk IVR designed by someone else. > > The application uses both func_odbc.conf and php agi to access an > external MySQL database. > > In the php routines, I would like to use the persistent connection that > is established in the dialplan, rather than creating a new connection > each time they run. How can I do this?You can't, they are completely separate processes and code. -- Joshua Colp Digium, Inc. | Senior Software Developer 445 Jan Davis Drive NW - Huntsville, AL 35806 - USA Check us out at: www.digium.com & www.asterisk.org
Then you should analyze why it takes 5s. Opening and closing a mysql connection should take at most a fraction of a second on a local net. BTW, classical web sites (plain PHP and HTML) do not maintain state, so keeping the mysql connection open may not be at all possible. I forgot whether open db connections get closed automatically after the web page has been rendered, but I think so. You could test this. For data processing you do not want to got through Asterisk. You could actually write your own db proxy, but I still think it makes more sense to find out why opening the db connection takes so much time. jg
On Tue, 3 Dec 2013, Don Kelly wrote:> Opening a connection in the php routines takes about 5 seconds, which is > unacceptable.One of my AGIs (written in C) reads 3 arguments from the command line, gets 4 channel variables, reads a row from the database, and sets 3 channel variables. On an AMD Athlon BE-2300 (a pretty low end processor), CentOS 4.9, Asterisk 1.2.37, MySQL 5.0.95 running on a separate host; 1,000 executions of this AGI takes about 16 seconds or about 0.016 seconds for a single execution. (60 per second.) On a VirtualBox VM (2 cores) on an Intel i7-3770, CentOS 5.9, Asterisk 1.2.40, MySQL 5.0.95 running on the same VM, 25,000 executions takes about 40 seconds or about 0.0016 seconds for a single execution. (625 per second.) Why does your AGI take 5 seconds? -- Thanks in advance, ------------------------------------------------------------------------- Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST Newline Fax: +1-760-731-3000