views:

373

answers:

8

Hi everyone,

I get more often the answer, when asking performance related stuff regarding PHP applications, that PHP really isn't the language for high-performance applications, and that a compiled language really is the way to go. The only thing holding me back to PHP is that it's what I have learned to work with for some while now and the development is quite rapid.

So, is PHP a thing of the past and should be put aside in web applications in favour of Ruby, for instance?

Update:

Premature optimization is usually what I have gotten as an answer when being too focused on optimizing stuff too early in the process, but I feel that it's quite far away from choosing the right language which has the best prerequisites.

Thanks

+20  A: 

Changing your programming language from one to another isn't going to result in massive performance increases or losses. Changing the way you write code is more likely to have much greater effects.

macek
+4  A: 

If you switch from PHP to Ruby, let it be for another reason than performance.

Ruby is not a compiled language either, and the last time I looked it was not significantly faster than PHP. If your language interpreter is the bottleneck, switch to a compiled language like C++, C# or Java.

Here are some random benchmarks.

Thomas
+1  A: 

I used PHP and switched to Ruby for other reasons than performance.

If this is what you want, take a closer look at what takes the time.

There are PHP solutions like the opcode cache xcache and a lib for Memcached that help you speed up your app.

Mr. Ronald
Hi Ronald, do you have any good links on Ruby that shows the pro/cons that were important to you?
Industrial
Four years ago we were looking for a good framework and as far as I can remember CakePHP wasn't around or pretty new. While I learned Ruby with Rails today I really like both. I even prefer Ruby over bash (tryed -) for scripting. PHP has many, many good points, but I's not that OOPish or straightforward. I really enjoyed starting web software development with PHP but today I favor Ruby. (very personal view)
Mr. Ronald
+8  A: 

There are tons of good reasons to switch from PHP to Ruby. Performance is not one of them. Some of the largest sites on the web use PHP. It's perfectly capable of performing well if you use it right.

If working on a high-performance application, there are many things to consider when optimizing for speed:

  • Where are your bottlenecks? At the database or application level?
  • Are you using caching to speed up requests?
  • Can you get a performance boost via load balancing or separating the database server from the web server. Hardware is cheap, programmers are not.
  • Consider using a performance optimized language on the back end, but keep using PHP on the front end.
Bryan M.
Hi Bryan, I am well aware about those steps and I have took all in consideration/use except the change of language, on previous projects. Would you mind share some info about why you think it's a good idea to switch to ruby?
Industrial
I really am not looking to start a why X is better than Y discussion. If you want more info, see google. If you're convinced PHP isn't fast enough, and thinking switching languages would help, Ruby is more of a lateral move. I would instead try something like C# or Java, which are compiled.
Bryan M.
@Bry @Ind nah, skip those wimpy emulated languages and go straight for a C/++ CGI! (yes, I'm joking)
Earlz
@Earlz, I suddenly became determined to write a web application in assembly language... how... strange...
Carson Myers
@Bryan I am more than aware about the mighty "my dad is stronger than your dad" discussion, but I would like to hear your opinion on these to get a grip of why you decided to move over
Industrial
My primary language used at the moment is PHP. It was a platform choice made by my company. My personal preference is for Ruby because I prefer OO languages, as well as the syntactic sugar it offers. However, I don't feel that writing PHP all day results in an inferior product. I also haven't had to struggle with any performance issues from either language. That's really all I'm gonna say on the matter.
Bryan M.
+2  A: 

As far as I know PHP is faster than Ruby (and Ruby is much more memory consuming). However I really love to write in Ruby.

In most cases PHP is fast enough. But for Facebook it wasn't fast enough, so they created they own solution and shared it. In my opinion for 99% of web applications PHP is enough. @macek has a good point!

klew
Hiphop-php is really interesting and I will check it out and try to get it running on a test environent asap!
Industrial
+1  A: 

When it comes to performance, the dispute between PHP and Ruby users is almost entirely religious and fanboy-ish. Which one of the two you use will probably not affect your performance that much.

More likely the problem is code that could use some cleanup and/or optimization.

If one writes slow PHP code, he or she will probably write slow Ruby code, too. It's not a matter of the tools but how they are used.

Techpriester
+3  A: 

Ruby and PHP are both late-binding languages, and while Ruby has some optimization over PHP, if you are having performance issues your code is the first place to look. Also, as Joel and Jeff once said on the podcast, if you can't identify your top five pain points with a language, you don't know enough about the language to justify learning an entirely new language for purely performance related reasons.

Daniel Ingraham
+1  A: 

Compiled code like C# can be faster but it seems like you can get stuff going (development wise) faster in Ruby. Stick with what you know, or if you want to be more marketable, pickup Rails or ASP.NET.

As with any web app, caching and client side code will make your app more responsive.

DJTripleThreat