Solved

How to improve performance of Adodb library in PHP?

Posted on 2008-09-29
4
995 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now