views:

223

answers:

5

I'm a student learning PHP. I basically make the stuff work, but never wondered about how the php.exe(on windows) works.

Does it compile the stuff it has to handle or not?

Reason I'm asking is because someone told me that ASP.NET has to compile all website-dependant data is has/receives, like everything that gets uploaded through a form. He claimed that PHP is faster on that subject, since it does not have to compile anything.

I can't find any good information on either subjects, so I'm asking here.

+1  A: 

Neither PHP nor ASP.NET normally compile (interpret as program instructions and convert to executable code) data received through forms.

Possibly your associate may be confused about the difference between compilation and data sanitization, or something. I really don't know.

chaos
+1  A: 

No. The type of data you are talking about is passed through to PHP as environment data from Apache. You can do it yourself with command line options to php.exe if you want.

Data is rarely compiled unless it is part of a resource for a program.

PHP itself is an interpreted language, which means that the code is never compiled into a machine-friendly format, it is simply scanned and parsed by the interpreter in order to be executed.

zombat
+5  A: 

Hi

PHP is a scripting language, and so is not compiled as such. It is parsed into an interal representation which is in turn "run" by the PHP runtime.

Your friend is correct in so far as that ASP.NET is compiled. However, it's only the actual program instructions that are compiled, not data. The way PHP and ASP.NET treat incoming (and outgoing) data are pretty similar in principle. If anything, ASP.NET will be faster than PHP because it is compiled, since compiled code generally runs faster.

Tor Haugen
+2  A: 

As @chaos has said, ASP.NET does not "compile" data received through a form.

Most likely what your associate is referring to is called ViewState in ASP.NET, and if that's that he's talking about, he's correct, although he mislabeled it as "compiling". ViewState does encode and store the state of the form and the server does need to decode this data and apply it to the object model. It uses this information to raise events that programmers can hook server-side, providing a much richer model for programming.

And, yes, this is a performance hit. PHP can be faster than ASP.NET; I've worked as a PHP developer and as an ASP.NET developer and I can attest to this.

But performance is not everything--more time is spent in data transit than it is in processing on a web server for all but a very few niche cases. And there are other aspects of your system that matter more than raw pushing power. ASP.NET trades that raw performance for other things.

This is where ASP.NET shines and PHP fails horribly. PHP cannot offer nearly the capability of ASP.NET for things like modularity, maintainability, security, re-usability, and general base library capability. Yes, PHP can be faster than ASP.NET. But ASP.NET is still superior.

Of course, ASP.NET sucks, too, IMO, but that's more because of some design decisions that I frankly disagree with. But I'd much rather use it that PHP any day of the week.

Randolpho
A: 

Tor Haugen is right, PHP is an interpreted language meaning the files remain as plain text on the sever and are interpreted as they are requested. ASP.Net is a bit of a hybrid because the *.aspx, *.ashx, *.ascx, etc. files are all interpreted while external libraries are compiled into DLL files that are then linked in like a normal desktop application. So if you have, for instance, several projects, one of which is an ASP.Net web application that relies on several class libraries, you would have several plain text files (web app files) and several DLL files that are generated and used by the server. You can use DLL files which PHP but it isn't as seamless. Usually such "class libraries" would simply be "included" as additional plain text files

Chris Thompson