Jump to content
  • Advertisement
Sign in to follow this  
Decrius

Apache, MySQL and ... C (or any other executable generating language)?

This topic is 3797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Since server load for sites can be heavy, and PHP can be quite slow, I thought of a WAMP server not made of PHP files, but executables. Just as a test for myself, on my own local machine, and to test how much difference it would make with heavy user load. What do you think? Would it be worth the effort or do you think PHP is just fine? I've seen some extensions for PHP to precompile the PHP scripts...same idea infact. I think it's worth a try :) Now I need to find out how ^^

Share this post


Link to post
Share on other sites
Advertisement
I suspect that for the purpose of generating HTML pages, a correctly optimized PHP install will outperform most hand-written C programs. After all, the PHP string model is designed for generating long strings.

On the other hand, ASP.NET works using compiled assemblies (though it can certainly compile them on the fly if required).

Either way, look into CGI for executing programs instead of scripts.

Share this post


Link to post
Share on other sites
Ah yes, thanks :). CGI should do it. A pitty I haven't found out how I can cross-compile on windows for linux :(

Why would PHP be faster? It has to intepret the PHP script first, then compile it and then run it. Wouldn't it be quicker if you have an .exe already being ready for use?

Share this post


Link to post
Share on other sites
Quote:
Original post by Decrius
Why would PHP be faster? It has to intepret the PHP script first, then compile it and then run it. Wouldn't it be quicker if you have an .exe already being ready for use?


Why would a plane get me to China faster? I'd have to buy the tickets, then go all the way to the airport and then board the plane! Wouldn't it be quicker if I just walked to China on foot?

First, PHP doesn't have to be interpreted-then-compiled. In low-performance server configurations, it's interpreted (but not compiled), which can be slow if there's a lot of script code but usually doesn't matter if your script is less than a hundred lines long. In high-performance server configuration, the code is compiled once and the resulting bytecode is optimized, so that the script acts as if it had been compiled to an executable. Then, there's the issue of caching: there's a risk that a CGI executable might have to be reloaded in memory entirely every time it's run, whereas a cached PHP script is already present in the server memory.

Second, there's the interpreter overhead, and there's the language support for string operations. A C program will most probably spend a lot of time malloc'ing strings all over the place before outputting them where required, not to mention the hassles of null-terminated string concatenation in linear time (it's quadratic-time by default). By contrast, string allocation in PHP is very fast (because it was designed for that purpose), and the output buffer system improves performance by an even wider margin. You'd probably have to spend a week or two optimizing a C program to outperform a non-trivial PHP script you've spend a single day writing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!