Fog Creek Software
Discussion Board




PHP vs ASP

I'm developing a web application for uploading and downloading images and associated information. I had started writing it with PHP, MySQL, Apache (on Linux) but the client insisted on ASP, MSSQL, IIS and Windows 2000, so I wrote an ASP version.
I now have 2 (unfinished) versions of the application and neither has been tested under
real life conditions (I expect a lot of traffic and the image files will be over 20mb each).
I'm predicting the performance of the PHP/Apache version will be much better. Is there any reason I should continue developing the ASP/Windows version? (Of course, if the client insists on Windows no matter what, that will be what they get.) I'm just wondering what other developers have experienced in comparing the 2 platforms for high-traffic web applications.

PC
Sunday, December 15, 2002

<<
I had started writing it with PHP, MySQL, Apache (on Linux) but the client insisted on ASP, MSSQL, IIS and Windows 2000, so I wrote an ASP version.
>>

Not to sound rude, but why did you start writing this application without clarifying/specifying the platform with the client? 

<<
I now have 2 (unfinished) versions of the application and neither has been tested under
real life conditions (I expect a lot of traffic and the image files will be over 20mb each).
>>

You could use Microsoft's Web Application Stress Tool to test both of these versions.  You say you 'expect a lot of traffic' - what does that mean?  You really need to have an idea of the target traffic - not only for the software implementation side - but also for the hardware side.  i.e. how many servers, what will you use for load balancing?  How about SSL traffic? high or low?  You may need/want an SSL Accelerator to take the encryption/decryption load off the web servers, etc.

<<
I'm predicting the performance of the PHP/Apache version will be much better.
>>

I doubt it will be much faster.  I think the majority of your execution time will be spent doing large I/O transfers than interpreting large amounts of script.  That is unless PHP's file handling calls are faster than ASP's. 

<<
Is there any reason I should continue developing the ASP/Windows version?
>>

Just out of curiosity, if speed is a major concern and you plan on having lots of traffic, and your clients want Windows, MSSQL, asp - why have you not considered ASP.NET?  It's compiled and is faster than classic ASP.  Contrary to popular belief you don't need Visual Studio.NET to create asp.net sites.  All you need is the .NET Framework SDK (Free from Microsoft's site) and SharpDevelop (free from http://www.icsharpcode.net/OpenSource/SD/default.asp)
You get output caching, compiled code, all for 'free' so to speak.

Just an aside - your personal bias against ASP shouldn't interfere with your client's needs/wants. (read:  You want to get paid right?)  I personally don't like ASP's syntax.  PHP is more like C++/Java/C# which is the style I prefer.  But in the end, if your client wants it written with a certain tool - use it. 

If you don't think ASP can handle high traffic sites, just visit Buy.com, Microsoft.com, bn.com ;-)  You server hardware & load-balancing scheme are another important consideration. 

Finally, I don't think you've given us enough information on the application/architecture to really say which one would be faster.  Sounds like a more thorough requirements analysis is needed. 

GiorgioG
Sunday, December 15, 2002

"(Of course, if the client insists on Windows no matter what, that will be what they get.) "

If you want to use PHP, and the client insists on Windows, why have you not considered running PHP/IIS?  ASP is not the server.  ASP is an ISAPI program that plugs into IIS.  PHP also can plug into IIS with ISAPI.  I've done it before.

For that matter, why can you not also run Apache on Windows?

What is the problem again?

Torment
Sunday, December 15, 2002

I see I didn't explain it well.
I think (maybe wrongly) that Apache for Unix/Linux is a MUCH better web server than IIS, and Unix is a MUCH better operating system than Windows. But maybe that's because I work in a place where they HATE Microsoft, so I never hear anything good about it.
There is ASP for Unix and there is PHP for Windows, so ASP vs PHP should not have been the subject. I mean Apache/Unix vs IIS/Windows 2000.

PC
Sunday, December 15, 2002

Hmmm.  Well you can also run Apache on Windows if you want.

As far as speed and scalability I don't think Apache has an advantage over IIS; in fact I think mosts tests show Apache somewhat slower.

Main reason Apache is thought preferable to IIS by many is because IIS has a bad history of security holes.  Not sure to what extent that's a concern now.  (I don't mean to suggest that IIS is up to Apache's level -- I have no idea whether it is or not -- just that I don't hear the panic-level concerns over IIS security anymore that used to be such a common occurrence.)

Herbert Sitz
Sunday, December 15, 2002

"For that matter, why can you not also run Apache on Windows?

What is the problem again? "

Exactly, what is the problem?  I tried to get the Apache Web server to work on Windows and couldn't do it.  Anyone here do it successfully?

Brian R
Sunday, December 15, 2002

I have installed Apache on 5 or so windows machines. 

Like all things the first couple of times you do it there are niggly frustrating problems, after that it's a breeze.

If I remember correctly the apache group, in their docs, recomend a linux install and specifically state they make no guarantees apache's behaviour in the windows environment.

The windows install was simpler for me than a linux install.

I develop php apps on a windows machine with mysql and then move them to a testing or production linux machine.

The biggest compatibilty problem I have had so far was when the linux and windows versions of php were different and session handling was no consistent across the two.

braid_ged
Sunday, December 15, 2002

I know there is Apache for Windows and I had installed it and started writing the application in PHP for Windows. But what's the point? Anyway, they insisted on ASP (after having agreed to PHP). So I got ActivePerl because I was not going to write it in VBScript.
What's wrong with PHP/Apache/Linux? Anyway, now I have both so I'm ready for them to change their mind several more times.
.NET is not an option because I'm not learning C# at this time since I'm in the process of learning JSP and Struts at work and my brain is tired.

PC
Sunday, December 15, 2002

If you want to write ASP pages, but you don't want to write them in VBScript then you can write them in JScript. Whilst most/all documentation for ASP is geared towards the VBScript programmer you'll find the class and method names to basically be the same in JScript (JScript is case-sensitive however).

http://www.4guysfromrolla.com/webtech/LearnMore/jscript.asp


If you don't want to write ASP.NET pages in .NET, but you don't want to write them in C# you can write them in... JScript.NET!

http://www.gotdotnet.com/team/jscript/


Major benefit: both client-side and server-side code is written in the same language.

Walter Rumsby
Sunday, December 15, 2002

Sorry

"f you don't want to write ASP.NET pages in .NET"

should be

"f you don't want to write ASP.NET pages in C#"

Walter Rumsby
Sunday, December 15, 2002

No, that wasn't right either :(

Oh well, perhaps

  WalterRumsbyPostTotal > GedBrynePostTotal

Walter Rumsby
Sunday, December 15, 2002

And don't forget J#. My understanding is that its an almost clone of Java.

marc
Monday, December 16, 2002

if you have the time, implement the system, using PHP as well as ASP, that way, if anyone asks for advice on using PHP or ASP....":-)

seriously, it is a good idea to implement in both versions, improves your understanding of both + something to put in your resume:-)

Prakash S
Monday, December 16, 2002

Just as a follow-up - I decided I wanted to test the whole PHP is faster than ASP.NET theory.  Now, keep in mind that this is a simple test, and as such, I'm not claiming anything.

Hardware:
Dell Inspiron P3-700, 256mb, 20gb

OS:
Windows 2000 Server w/SP3

Web App Server Configurations:
ASP.NET 1.0 (IIS 5.0 + .NET Framework)
PHPTriad (Apache 1.3.23 + PHP4)

Testing software:
Microsoft Application Center Test

The test consisted of 1 page per server (index.php & default.aspx) and each does the following:

1. retrieve a querystring variable called 'test' and print it + an html BR tag.
2. iterates through a for loop (0 to 99) tests for odd/even number and displays the result.


Here's the PHP code without the html/head/body/br tags ( don't think joel's forum code can handle/deal-with it?)

$qry = $HTTP_GET_VARS['test'];
echo $qry, // br tag

for($i=0; $i<100;$i++)
{
    if($i % 2 == 0)
          echo $i ," is an even number."; // + br tag
    else
          echo $i, " is an odd number."; // + br tag
}


Here's the ASP.NET code:

string qry=Request.QueryString["test"];
Response.Write(qry); // +br tag

for(int i=0; i<100;i++)
{
  if(i % 2 == 0)
    Response.Write(i+" is an even number."); // +br tag
  else
    Response.Write(i+" is an odd number."); // +br tag
}

The test:

The Microsoft Application Center Test software allows you to script testing processes.

The test script I made simply calls the page up and passes a number in as the 'test' querystring variable.  It created 1 request of which loaded & then refreshes the page (using same connection) 1000 times (or until the test time limit is reached.)  If time allowed, the process repeated itself.  I set up the test to run for 1 minute  (+ 10 seconds of 'warmup' time which did not show up in the results)

When leaving the 'test' querystring blank, the PHP result page was 2514 bytes in size and the aspx (.NET) page was 2589 bytes in size.

As a general comment - Apache+PHP had pretty horrible performance and I can't really figure out why.  The CPU was maxed out by both web app server tests during these tests.

Apache/PHP:
Peak Requests Per Second (RPS): 17
Average RPS: 16.15.
Average bytes received/sec: 44,421.
Total # of Requests in 1 minute test: 969.

ASP.NET:
Peak Requests Per Second (RPS): 270
Average RPS: 234
Average bytes received/sec: 650,503.
Total # of Requests in 1 minute test: 14,090.

All requests returned Response Code 200 (request completed successfully) for both web app platforms.


Conclusion:
It would appear that ASP.NET is faster at what was tested.  I tried tweaking apache, but apache wasn't the issue (I pointed the test at apache's default (static) index.html in the htdocs directory and it was registering 300+ RPS)

Is this a real-world test?  No.  Your Mileage May (and probably will) Vary.  I haven't had a chance to test any database stuff out yet - I might get to that tomorrow if anyone's really interested.  Maybe it'd be faster on a Linux box? Maybe this version of PHP is broken on Windows - I'm not sure. 

GiorgioG
Monday, December 16, 2002

<quote>
Exactly, what is the problem?  I tried to get the Apache Web server to work on Windows and couldn't do it.  Anyone here do it successfully?
</quote>

Apache is pretty easy to setup on Windows, actually easier than on Linux. They have a Windows install program that you just download and run and then: behold, Apache is running!

You can set it up as a service is you run Windows NT/2000/XP.
You still have to configure it using a text editor to edit the server.conf, or whatever that file is called.

With the new Apache 2 version the Windows version is not beta anymore so the preformance and stability should be good.

That's what I could contribute about Apache on Windows. Hopes it helps somebody.

Rasmus

Rasmus Grunnet
Monday, December 16, 2002

PC, in an earlier thread you condemned a programmer you sacked after just two weeks on the grounds he was trying to tell you what to do.

As a matter of interest, where did that programmer sit regarding this debate you're now holding here?


Monday, December 16, 2002

<<GiorgioG's PHP/ASP.NET benchmark test>>
Oh dear, oh dear, this is worse than cargo cult science...

About ASP.NET vs PHP: Both are excellent for developing web applications and roughly have similar performance if configured properly. I would stick to whatever you're best at, because that would be the most costs efficient solution for the client. If your client really wants Windows/ASP.NET I would give it to them.

Jan Derk
Monday, December 16, 2002

[Maybe it'd be faster on a Linux box? Maybe this version of PHP is broken on Windows]

You should not be comparing PHP for Windows to ASP for Windows. ASP was developed originally for Windows, PHP was developed originally for Unix. And I was really asking about Apache for Unix vs IIS for Windows.

[PC, in an earlier thread you condemned a programmer you sacked after just two weeks on the grounds he was trying to tell you what to do. As a matter of interest, where did that programmer sit regarding this debate you're now holding here?]

Actually, that is not what happened. He worked for me 3 years ago and I never fired him, I just didn't have any extra work for a year after 9/11.
He had no opinion on things like ASP vs PHP or what web server is better. It takes a lot of experience and/or research to know that kind of thing. I have done lots of PHP and Java but this is my first ASP, so this will be my first chance to make the comparison for myself. And it couldn't hurt to ask here also.
 

PC
Monday, December 16, 2002

It might be a bit unusual, but I have a legacy IIS5.0/PHP4.1.1 (CGI) CMS style app. It is just for a collection of very small sites (you know, one hit every few centuries) and performance is not an issue in this setting. I did notice however that when files are being uploaded, for some reason the CPU (PIII 1Ghz) on the box goes to 100% for the PHP process and stays there for the duration of the upload. This is "a bad thing". Why is PHP polling the bejeezus out of this box? I do not know if the same thing seems to be true for different versions of PHP.

P.S. I know there is a ISAPI version of PHP for IIS, but in the docs it is always refered to as fast but unstable, hence the CGI install

P.P.S. When I stress test the app (walkthough of some typical browsing) the server ( Dell PE 2500, 1 Ghz, 512 Mb, 15000 RPM SCSI) maxes out at around 14 req/sec. , bottleneck is CPU .

Just me (Sir to you)
Monday, December 16, 2002

From earlier thread:
PC [concerning the programmer you'd hired]> it was an application I had been developing for about 2 years, and I had already been a web programmer for over 6 years.

From this thread:
PC> He worked for me 3 years ago and I never fired him, I just didn't have any extra work for a year after 9/11

So you hired and fired this guy 3 years ago (1999), and you were a web programmer for 6 years before that, right? So you've been a web developer since 1993 then? That's pretty impressive. You shouldn't have any problem picking up ASP of any dialect then. I'd think someone that's been doing this for ten years would be an expert, considering how easy web programming is.

Troy King
Monday, December 16, 2002

My experience of running PHP on Windows under both Apache and IIS is that I'd only use it in that configuration for a development environment. Under IIS, I've tried various versions of the ISAPI driver, and haven't yet got it to work reliably, so it's reasonable to expect the CGI version to be slower.

I've also experimented with Halcyon's ASP on Linux, and it works quite well, but occasionally gets a "VBScript Interpretation Error" that I haven't been able to track down (if anyone knows what causes this, please give me a shout). (Hmmm, just did a Google search on "VBScript Interpretation Error" and my site came up as the number 1 entry).

However, I think both solutions are going to give poor performance compared to their native environments, and I certainly wouldn't try benchmarking them against each other. If I wanted to conduct a fair test, I'd give identical hardware to a Linux/Unix guru and a W2K guru and ask them to build the optimum configurations, then write equivalent test scripts in each.

I think the test should include database tests, and it would be important that equivalent databases be used. For example, I would expect MySQL to be faster than MSSQL, however MySQL lacks Locking, Transactions, Referential Integrity, Stored Procedures and other essential features of enterprise databases. I'm happy to use it for web counters, and forums, but I would not trust it with any important data.

Of course, security should also be factored in the test. I'm not sure how you would test this, but I would certainly stipulate that the servers must be patched for all published security holes.

I would be very interested in seeing an independant objective test (i.e. not sponsored by Microsoft, or run by a Linux advocacy group), conducted along these lines.

Oh, and just to state my personal position, I run sites on both Linux/Apache/PHP and W2K/IIS/ASP/.NET, and both are excellent solutions in their own right, and configured properly, both give excellent performance.

James

James Shields
Monday, December 16, 2002

"I would be very interested in seeing an independant objective test (i.e. not sponsored by Microsoft, or run by a Linux advocacy group), conducted along these lines."

You mean someone should do a PHP PetStore :-).

Just me (Sir to you)
Monday, December 16, 2002

If you're worried about speed....

# Sure, using $qry would be easier, but it's also an additional
# operation and doubles the needed resources for one value.
# Also, HTTP_POST & HTTP_GET are deprecated starting at
# version 4.2. The engine may be taking time to figure out what
# you mean by 'HTTP_GET_VARS'.
echo $_GET['test'].'br';

# ++$ is faster than $i++.  Besides, is there really a reason for
# returning the value then incrementing it in this case? Post
# incrementing should also cause additional iteration
# if i"m not mistaken.
for($i=0; $i<100;++$i)     
{
    if($i % 2 == 0)
        {  echo $i ; ?>  is an even number.<br><?php }
    else
        { echo $i; ?>  is an odd number.<br><?php }
}

# It is also faster to drop into HTML mode to display text then just
# echoing it out.

As for the rest of the dismal performance, are you running php as a cgi on the windows box? Is it even possible to run it as a shared module on a windows boxen? It would probably be more fair to test php and IIS as IIS and Apache both take a different approach to serving pages. Apache forks child processes where as IIS spins new threads. How Apache does this on Windows could be an issue as well.

I use Apache on Linux boxes and have allways seen stellar performance.  But getting into the Windows realm, I can't really say.

Cheers,
BDKR

BDKR
Monday, December 16, 2002

As for this....

>>>
I think the test should include database tests, and it would be important that equivalent databases be used. For example, I would expect MySQL to be faster than MSSQL, however MySQL lacks Locking, Transactions, Referential Integrity, Stored Procedures and other essential features of enterprise databases. I'm happy to use it for web counters, and forums, but I would not trust it with any important data.
<<<

MySQL and MSSQL both perform VERY VERY well. As a *nix guy, I have no problem admitting that MSoft got it right with MSSQL.

However, MySQL myIsam tables lack transactions and rerential integrity. Innobase tables do not. Therefore Locking, Transactions, and Referential Integrity are all possible with MySQL. The only one that's not there yet is Stored Procedures.

Just some updated 411 for ya'.

Cheers,
BDKR

BDKR
Monday, December 16, 2002

To be fair, this morning I installed Apache 2.0.43 + PHP4.2.3 + Zend Optimizer on the same test environment as listed in my previous post and got much, MUCH better performance out of this test:

Average RPS: 127
Total # of Requests (in 1 minute test): 7665

Still not as fast as ASP.NET, but at least it's not a joke like the previous test indicated.  Though it may be faster on Linux, I don't see it being twice as fast, so I still have to give ASP.NET the edge overall.

GiorgioG
Monday, December 16, 2002

You can get higher performance out of your php test by using a php accelerator (try http://www.php-accelerator.co.uk/ ). The accelerator caches the parsed version of the php page so that it doesn't have to be re-parsed on subsequent requests. This will lower the CPU load quite a bit. I have seen 3x performance improvements with the accelerator. (BTW, the ASP engine does this automatically)

igor
Monday, December 16, 2002

igor:

<<
You can get higher performance out of your php test by using a php accelerator (try http://www.php-accelerator.co.uk/ ).
>>

I was under the impression that Zend Optimizer is such a php optimizer?  Zend didn't seem to have much of any performance impact on the test however (I did verify it was working.)  Unforunately the php accelerator you linked to does not have a Windows implementation (yet).

GiorgioG
Monday, December 16, 2002

I'm just curious... has anyone tried implementing PHP as a CLR language yet? It's the sort of thing that ought to be fairly easy to do. It might not be so easy to make .NET show PHP pages unchanged, but the language itself outgh to be easy.

James

James Shields
Monday, December 16, 2002

James,

I'm not sure it would really make any sense to convert PHP to the .NET CLR.  Performance wise - you have little to gain - which is why classic ASP was not converted to the CLR.
The syntax isn't terribly different from C# so the question would then be why bother - especially if existing PHP code had to be modified anyway to get it to work with "PHP.Net"

GiorgioG
Monday, December 16, 2002

<<
Performance wise - you have little to gain - which is why classic ASP was not converted to the CLR.
>>

Apparenly my coffee hasn't kicked in yet.  Of course ASP.NET is faster than ASP so on a performance level, ASP would certainly benefit from being implemented with the .NET Framework/CLR.  I'm not sure it makes sense though to implement PHP on .NET if it isn't going to be 90-100% compatible. 

GiorgioG
Monday, December 16, 2002

Don't use PHP and Apache on Windows. That defeats the whole thing. Just finish up on ASP/Windows and move on. The bandwidth clgo is going to have a *lot* more to do with how you design the uploading and downloading which will probably be more of a raw FTP thing. There is no way a service that moves 20MB files is going to get a whole lot of traffic outside of the actual file x-fers.

pb
Monday, December 16, 2002

GiorgioG -

back in the day (2000?) Zend Optimizer focused soley on code-level optimizations (like removing unreached functions and whatnot, i guess). Even w/ zend optomizer PHP would interpret each page from scratch on every request, meaning that performance of the application dropped off with the size of the pages (including includes). At that time I was looking at PHP, this was a big problem for me. I assume someone's come up with a solution by now.

Matt Christensen
Monday, December 16, 2002

It sounds to me like you might not be as proficient in ASP as you are in PHP, and you are looking for excuses to give the client a PHP site when he wants the system developed in ASP. If there was a significant reason to do so (for example performance) then fair enough, but since everyone has agreed that isn’t the case, I think you should give the client what they want.

I also don’t think writing the solution in ActivePerl was a good idea, there are a heap of ASP programmers out there that your client could use down the line to maintain/enhance this application, but the majority of these programmers would work with VBScript. Again, it sounds to me like this was the better option for you, not the client.

Ben
Monday, December 16, 2002

Yeah, Ben, but PC has over 7,350 years of experience in Web programming, so he obviously knows better than the client what the client wants. Silly you.

Troy King
Monday, December 16, 2002

Hehe Troy.  I can just see him now, designing his first web page for the Stone TabletPC 2002BC edition...

GiorgioG
Monday, December 16, 2002

I tell you, it was hard being one of the first.

PC
Monday, December 16, 2002

>I'm not sure it makes sense though to implement PHP on .NET if it isn't going to be 90-100% compatible. 

You're probably right. A lot of ASP will port to .NET fairly easily, but one thing it does not like is:

<%
Do While Condition
%>
    <p><%= Condition %></p>
<%
Loop
%>

You can't have repeating sections of HTML. I think it's because the source is compiled and merged with the HTML on the fly. On the one hand, I agree with the .NET approach of seperating the source from the HTML template. ASP and PHP applications can get very messy as they get large.

I recently wrote an ASP.NET component which needs to be shared by several applications. I was able to seperate the HTML from the code completely and distribute the code as a DLL. It meant the HTML components could be customised to match the look of the applications, and updates to the code can be distributed without losing the customisations.

So getting back to "PHP.NET", would there be a point? Yes and no. It would allow PHP programmers easier access to .NET. However, if the incompatibility problems could be overcome and PHP programs could run well under .NET, it would be the ideal way to run PHP on Windows.

James

James Shields
Tuesday, December 17, 2002

Hey James,

There is this project.

http://www.akbkhome.com/Projects/PHP_Sharp?click=yes

It's called PHP_Sharp. Haven't spent a lot of time there so couldn't give you a ton of details, but it's still in it's early stages.

Cheers,
BDKR

BDKR
Tuesday, December 17, 2002

*  Recent Topics

*  Fog Creek Home