2007-07-16 19:33:14
I have heard many good things about the PHP Data Objects (PDO) extension which provides a data-access abstraction layer allowing you to use multi databases through the same functions - I am going to be using MySQL.
I will only be doing one simple test - connecting to the database. Using the Apache benchmarking tool ab you can generate many concurrent requests to any script on your server.
/usr/local/apache/bin/ab -c 5 -t 20 http:/your.host/db-test.php
This will run 5 concurrent connections for 20 seconds.
In the first test i compared a standard PDO connection to MySQL with no additional options against a standard MySQL connection.
$oDatabase = new PDO('mysql:host=localhost; ',DB_USER,DB_PASS);
$oDatabase = new mysqli('localhost', DB_USER, DB_PASS);
Lets start with our standard MySQL connection
Concurrency Level: 5 Time taken for tests: 20.7439 seconds Requests per second: 629.22 [#/sec] (mean)
Not bad - that shows that the script can handle 629 concurrent connections. Now for the PDO class
Concurrency Level: 5 Time taken for tests: 20.780 seconds Requests per second: 702.32 [#/sec] (mean)
Even better! That's an extra 70~ connections a second - now lets see how much we can push it. First we turn on ATTR_EMULATE_PREPARES.
Requests per second: 708.76 [#/sec] (mean)
And now the one that should provide the biggest increase ATTR_PERSISTENT
Requests per second: 923.46 [#/sec] (mean)
Straight away we can see a big jump from the standard connection (629) to our PDO class (923) that's almost 300 extra connections every second!
With the preliminary testing done I am defiantly going to further investigating PDO. I will be reporting back at a later date with a more detailed comparison.