For a good while, I have used PHP with a Microsoft SQL Server 2008 database on the back end. Microsoft have taken a keen interest in PHP and have contributed a great deal to the PHP community, none more so than by creating the Microsoft SQL Server Driver for PHP.
Before starting the latest project for our company, we chose to go down the route of PHP and Microsoft SQL Server 2008. Which creating the foundation for the project I encountered a very simple problem, which is best to use: the bundled mssql extension (php_mssql.dll) or Microsoft's own SQL Server Driver for PHP extension (php_sqlsrv*.dll). After a good while searching on Google for some comparisons between the two, I came up empty. In the end I decided we should use the classic mssql extension as it would be easier to install on client servers than an additional dll.
We have now completed this project, but since the project started, PHP 5.3 has been released and PHP is now compiled both with VC6 and VC9. Eventually the VC6 builds will be phased out (PHP 6 for example). With a bit of spare time, I wrote a simple test that would give me the speeds of the 2 drivers with some surprising results.
The Test
Pretty simple, write 2 classes with the same method names that call pretty much identical functions of the 2 extensions. A third file would be the main test. It would loop round a few hundred times. Each time it would load one of the classes, connect to the database, perform a series of tasks, disconnect and log the time taken to perform the query.
Before the test started, I created a new database with a single table with 4 columns.
The tasks were:
The Results
The test was run 1059 times against each extension. The average time is as follows (time in seconds, lower is better):
MSSQL (PHP bundled MSSQL extension) - 15.41713099
SQLSRV (Microsoft SQL Server Driver for PHP) - 16.76840312
From this test we can conclude that the original MSSQL extension is 8.76% faster than the newer Microsoft SQL Server Driver for PHP.
Now before everyone goes and changes back to MSSQL from SQLSRV, you should remember that the new extension has many new features, which if used correctly could make your database lookups more efficient. The main MSSQL draw back that I have found is that column names are truncated to 30 characters. Going forward, PHP 6 most likely won't support the original MSSQL extension (as PHP 6 will only be built using VC9).
Please remember that I can't guarantee the accuracy of the results, but I'm going to make the most of them just now! Comments always welcome :)
Comments
Excellent post
Thank you