PHP and MSSQL - Speed

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

PHP and MSSQL - Speed

Post by Sephern »

I've recently taken to creating a C# application which acts as a basic proxy server. It takes input from a client and then inputs it into the database, based on a variety of parameters.

In order to test how much latency this placed on the activities, I proposed a basic test. One of the simplest (yet most used) activities this system will be doing is registering new accounts. There is a stored procedure in the database which carries out this task. The C# application uses this stored procedure to make accounts based off the input from the socket.

The test was simple.

I created a PHP script that took in the required fields, and then created an mssql connection. I then bound the relevant fields to the parameters in the stored procedure, and executed it, thereby testing the speed of registration on a direct PHP to Database connection.

I then used the same fields, and sent them through sockets (in PHP) to the backend system, which dealt with the database connection and query.

The C# backend was .3 of a second quicker. This was pretty much the opposite of what I was expecting. The backend deals with several overheads PHP does not have to do (checking the packet is structured correctly, splitting it into individual fields, etc), yet it still finished quicker than the PHP to Database direct connection.

Am I correct in thinking that this is because the library C# uses to connect/execute MSSQL statements is more efficient than the one used in PHP/because C# is designed to use MSSQL better than PHP is? Would this simple test therefore yield different results should I use MySQL? Is there any other miscellaneous information I should know about what causes it?

Thanks for the help ^_^
saledekho
Forum Newbie
Posts: 4
Joined: Tue Mar 23, 2010 2:48 am

Re: PHP and MSSQL - Speed

Post by saledekho »

no doubt PHP is fast comparison to C# or other languge
PHP Is fast because we know

PHP is a OPEN source language.
PHP have more supports than C#
and
PHP is more secure language than C#

Thanks
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: PHP and MSSQL - Speed

Post by ell0bo »

Well, C# -> .NET should be faster in the backend because it's a compiled (or pre-compiled) language. PHP is however retranslated every time, so there is over head. If you want to do a proper test, you need to remove that variable from the equation so you should use something like APC so the byte code is getting cached.

You SHOULD see a speed up the second time it runs as apposed the first time.

Now, however, if you're talking about the actually speed of connections, if you're just timing creating a socket and the transaction, I'm amazed the it could be .3 seconds faster, unless you're doing 1000 transactions or something of the sort.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: PHP and MSSQL - Speed

Post by Sephern »

In real conditions on a website, a registration page, in this example, would be programmed to use the mssql stored procedure, and therefore this is what I used in creating a PHP to database page.

The backend is simply a proxy. PHP sends data to it, and it records it in the database.

In terms of timing. I timed from the point the PHP script received data from the form, to the point where the script finished. As this entailed receiving feedback from the C# app, this meant that the time it took for that to access the database, check the record didn't already exist, create it, and reply was also factored into the time it took for the script to execute.

As for saledekho, please don't make comments which have no factual basis whatsoever. Thanks.
Post Reply