Solved

How to improve performance of Adodb library in PHP?

Posted on 2008-09-29
4
1,000 Views
Last Modified: 2013-12-12
We were using Adodb in the backend of our enterprise application.

When we started testing we noticed that with 2000 requests made simultaneously,
CPU usage on server is 99.6% which is very high and also error rate is high.

But when we do the same testing using the builtin mysql commands in PHP,
CPU usage on server is less than 26%.

The ADODB abstraction library is drastically decreasing the performance. Can anyone suggest tweaks to improve the performance of ADODB because we cannot remove ADODB from our application.
We tried some tweaks suggested in internet but it did not work.
Reply as soon as possible.
0
Comment
Question by:manajitrath
4 Comments
 
LVL 29

Expert Comment

by:fibo
ID: 22596761
Do you close the adodb connection after use?

Can you paste some of your code so that we might find hints?
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 22598725
As ADODB consists of multiple php files which are read and parsed every time it is very time consuming. Try using a PHP-Code cache like
http://pecl.php.net/APC
http://eaccelerator.net/
Zend Platform http://www.zend.com/

Also using the ADODB will be more CPU-intensive than native mysql as most of the part is written in PHP and not in C like the native function.
0
 

Assisted Solution

by:lepricon
lepricon earned 250 total points
ID: 23024184
As obtained from the PHP ADODB Documentation
-------------
High Speed ADOdb - tuning tips

ADOdb is a big class library, yet it consistently beats all other PHP class libraries in performance. This is because it is designed in a layered fashion, like an onion, with the fastest functions in the innermost layer. Stick to the following functions for best performance:
Innermost Layer

Connect, PConnect, NConnect
Execute, CacheExecute
SelectLimit, CacheSelectLimit
MoveNext, Close
qstr, Affected_Rows, Insert_ID

The fastest way to access the field data is by accessing the array $recordset->fields directly. Also set the global variables $ADODB_FETCH_MODE = ADODB_FETCH_NUM, and (for oci8, ibase/firebird and odbc) $ADODB_COUNTRECS = false before you connect to your database.

Consider using bind parameters if your database supports it, as it improves query plan reuse. Use ADOdb's performance tuning system to identify bottlenecks quickly. At the time of writing (Dec 2003), this means oci8 and odbc drivers.

Lastly make sure you have a PHP accelerator cache installed such as APC, Turck MMCache, Zend Accelerator or ionCube.

Some examples:
Fastest data retrieval using PHP      Fastest data retrieval using ADOdb extension

$rs =& $rs->Execute($sql);
while (!$rs->EOF) {
      var_dump($rs->fields);
      $rs->MoveNext();
}

      

$rs =& $rs->Execute($sql);
$array = adodb_getall($rs);
var_dump($array);


Advanced Tips

If you have the ADOdb C extension installed, you can replace your calls to $rs->MoveNext() with adodb_movenext($rs). This doubles the speed of this operation. For retrieving entire recordsets at once, use GetArray(), which uses the high speed extension function adodb_getall($rs) internally.

Execute() is the default way to run queries. You can use the low-level functions _Execute() and _query() to reduce query overhead. Both these functions share the same parameters as Execute().

If you do not have any bind parameters or your database supports binding (without emulation), then you can call _Execute() directly. Calling this function bypasses bind emulation. Debugging is still supported in _Execute().

If you do not require debugging facilities nor emulated binding, and do not require a recordset to be returned, then you can call _query. This is great for inserts, updates and deletes. Calling this function bypasses emulated binding, debugging, and recordset handling. Either the resultid, true or false are returned by _query().

For Informix, you can disable scrollable cursors with $db->cursorType = 0.
---------------
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I make this form submit to itself? 10 35
mysqli_connect error on wamp but not on remote server 8 37
Why is my wamp get_include_path() wrong? 2 21
Currency in SQL? 2 30
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question