PHP PDO API Calls
# December 3, 2012 at 7:30 pm
* How would I determine how much time is being spent in each PDO API call? I am aware of differentiating the amount DB execution time from the amount of time in each API call. (Interested in another other option)
* How would this solution impact the maintainability of my application? Specifically, if a new framework is added to the application how would this solution time PDO calls in the framework?
* In what ways could this solution change the performance characteristics of my application?*# December 3, 2012 at 10:25 pm
$start = microtime( true );
/* do PDO stuff
* (it will likely be necessary to perform
* the same task repeatedly, in a loop,
* to get a meaningful time period).
$stop = microtime( true );
$execution_time = $stop – $start;
As for the rest of your post, I am unsure what your actual question is, so this may or may not apply:
The single most time-consuming portion of any database API, by *far*, is the part where it actually queries the database. The process of sending a query, waiting for a response, and receiving the result can be called a “round-trip.”
If you want to speed up your database-related code, simply rewrite your code to make as few round-trips as possible.
… never use multiple queries where one would do (e.g., INSERT multiple records with the same statement)
… use JOINs and MySQL functions (aggregate functions, etc.) to combine queries involving multiple tables
… use TRANSACTIONs and multi-step queries (this is the main reason I prefer MySQLi over PDO: transactions and multi-queries are much easier)
… don’t query the DB when you don’t have to (this may seem obvious, but I see it all the time).
You must be logged in to reply to this topic.