Solved

How to improve performance of Adodb library in PHP?

Posted on 2008-09-29
4
1,003 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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.

756 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