• PHP vs. Ruby on Rails: Update

    May 15 2007

    It's now been six months since I announced I had switched from PHP to Ruby on Rails. Reader Richard Wayne Garganta wrote me to ask:

    So, now that you have worked with rails a while - are you still in love with it? I tried it a while back and found out my biggest problem was deployment. I have considered returning to it. Your opinion?

    Originally, I decided to start using rails because I was getting bored doing server-side development. I asked myself, why was it so much fun to program in JavaScript, but so boring to program in PHP? I figured it might be the programming language itself that was boring me, so I took a stab at learning Ruby on Rails.

    Ruby is a really great dynamic language that is fun to work with (though somewhat tricky to get used to). Rails is a great framework, especially when it comes to using ActiveRecord to simplify working with complex data models. I think that Ruby on Rails is a great way to build a complex web site.

    Rails also makes it much easier to set up tests (which I was pretty lazy about) and have separate development and live environments. There's a lot of great solutions to common web development problems that makes Rails a lot more fun to work with, especially on big projects.

    Eventually I realised that server-side programming in Rails, while a bit easier and more fun, was still server-side programming. Even though I didn't have to worry about writing SQL and building forms, the types of problems and challenges were basically the same as in any server-side language. I realised that even a new language and framework wouldn't change server-side programming altogether. At the end of the day, I still have a lot more fun coding with JavaScript, Ajax, CSS and HTML.

    Lately, though, I've been having a lot more fun coding simple templates using PHP. There's something kind of simple and sweet about making a page dynamic by just by putting a few lines of code in a standalone template. MVC is the only way to build a large site or application that is easy to manage, but if you're doing something simple, it's definitely overkill. It's no surprise that the 37signals and Ruby on Rails web sites run on PHP.

    So the moral of the story? Use Ruby on Rails for applications, use PHP for simple web sites, and don't use either of them if your passion is client-side development. :)

  • Comments

    1. Frederico Padilha at 6:08pm on May 15, 2007

    Hi Jesse,

    Lately I've been researching about programming languages so I could decide which server side language I would concentrate my efforts on. Also, I've read some experiences like yours in other blogs and I recently made my mind. I chose to keep up with PHP (which I have some intermediate knowledge).
    A lot of people say that RoR is really something that simplifies things but many said that if you need to get specific you will suffer more from lack of community and for the structure of the language itselft. The majority of web development companies that I've contact with usually sticks with ASP.NET in the end, they say it's because its cheaper in the end, including cheaper in terms of time lost with server-side scripting.
    I chose PHP because I just love open source and PHP is far from any web language in that matter, there are so many open source CMS that you go crazy, and I've evolved my PHP so that I can now understand and change what I need. Now I've bought come books and tutorials to really go deep.
    I hate server-side scripting, but to know it well gives me power to really get into open source and do whatever I want without the need to structure an entire site in PHP.
    I've done many sites using Wordpress, in the end you don't even imagine that Wordpress code is behind it.
    My opinion is that client side programming rules, althought I just fool around with Java, I still love and dominate CSS and XHTML.. In the end every language gets the job done, you just have to identify yourself with it and its benefits and downsides. Now my routine is HTML, CSS, PHP, some Javascript for forms and interaction, Photoshop and rarely some Flash, although 70% of the site proposals that come to me are about Flash sites, today I'm turning them down to learn how to make some really powerfull websites! Although Flash is so fun and actionscript is quite simple for what I usually need!
    Well, congrats by the post as always, and by that tut on IBM that I finally read =)!

    2. Geof Harries at 7:47pm on May 15, 2007

    I'd suggest that RoR is not only for applications, but also for big sites, such as those with a substantial user base and complex business logic. PHP can certainly be structured so that it is easier to maintain and add to over time, but too many people think quick 'n dirty is good enough. That is, until the site implodes and trying to get the system to work is way more effort than starting from scratch. The strictness of RoR is a blessing in disguise.

    3. Aaron Bassett at 12:34pm on May 16, 2007

    Geof: RoR for big sites. O Rly?

    It is not a flaw in php which produces "quick 'n dirty" code, its a flaw in the programmers ;)
    I'm sure that a programmer could produce just as much bad code in RoR as php...

    And as for the 'Big Sites' issue, have you not been keeping up with the problems large sites have been having scaling with Ruby? (google twitter scaling issues)

    4. Geof Harries at 10:42pm on May 16, 2007

    Aaron, I'm not commenting on RoR's technical ability to scale, rather that it forces you to use a framework by default. PHP, on the other hand, does not. That's not to say you can't build with a PHP framework, just that many developers, especially young and unexperienced ones, don't even bother.

    5. Jennifer M. at 1:11pm on May 20, 2007

    I agree with Aaron - it's the way large sites have been developed.  I've seen too many large applications built "quick n dirty" with PHP at first, to prove the model.  And then they become monsters because code is tacked on and tacked on and nothing is cohesive.  There was no development plan.

    At that point, when the code becomes unmanageable, companies (unfortunately) turn to MS because of its rapid dev environment. 

    I really wish a PHP-driven or PHP-like rapid dev environment would "make it big" and prove that MS isn't the answer for large apps!  Look at MySpace-- trying to run on Cold Fusion - HA!

    6. I L at 4:33am on May 24, 2007

    Jennifer -

    MySpace has been running ASP.NET for years.

    And Jesse, I'm just popping in to say hi - I'm the complete opposite of you. I can't stand JavaScript. It's the devil!

    7. I L at 4:33am on May 24, 2007

    *about a year. Sorry. ColdFusion couldn't handle it anymore, and after switching to .NET their capacity shot up a lot.

    8. SoftMind at 1:36am on June 16, 2007

    Hi,

    I am looking badly to start with IronRuby Next month. I need to have best of both the worlds. DotNet as well as Ruby. I am just puzzled with few questions, i hope smeone can just answer it here.

    Do I need to learn only Ruby OR ( Ruby + C# ) to take the addvantage of IronRuby.

    Will Ruby developers work straight away with IronRuby, without any C# or VB.Net Knowledge.

    Can some kindly blog Few PreRequisites, so that ruby dvelopers can get prepared to work with IronRuby when released.

    I am just confused, can any one guide me. Plus... where can i read regular progress on IronRuby.

    Once i start working with IronRuby, will i get more advantage than RubyonRails or Less Advantages..?

    Thanks

    9. Jake at 12:24am on June 28, 2007

    I disagree with with "PHP for simple web sites". You can use erb (embedded ruby) just the way you would use PHP, but you get the beauty of the Ruby language. It is cleaner and more powerful. Or you can use the Camping framework that was developed for smaller sites.

    I used to program in PHP but I started looking around for other options because the language itself is really clunky and it was more than I could take. I am much happier now.

    10. John at 6:01am on July 4, 2008

    <a href="http://bestglobalmeds.fateback.com">Health Tips</a><br>I'd like to get <a href='http://womenshealth.siteburg.com/clomide.html'>clomide</a>.  Where I may find trusted e-shop?

    11. John at 6:01am on July 4, 2008

    <a href="http://bestglobalmeds.fateback.com">Health Tips</a><br>I'd like to get <a href='http://womenshealth.siteburg.com/clomide.html'>clomide</a>.  Where I may find trusted e-shop?

    12. jamie at 9:24am on October 29, 2008

    I hate server side scripting. I'm an artists by heart and soul and imagination, and if I'm to code then the coding must be an architecture of art. XHTML, CSS, the beauties. But now, clients are bringing in more job proposals requiring server side scripting skills.
    I've never really liked php, it just looks pretty scary with that dollar sign preceding every tag. I've been reading a book on ruby on rails and its sounding pretty fun, compared to the O'Reily books on PHP i've read which make snore halfway through the preface.
    But what I need to know is, can ROR really deliver much more than PHP?

    13. Vitaly at 5:25pm on October 10, 2009

    I have worked with PHP since version 3 and worked on very big projects involving hundreds of thousands of lines of code and I agree PHP is capable to support and scale big code bases. PHP evolved very much from version 3, and now there are a dozen of PHP Framework out there but PHP remains to be more structured and dirty language if compared with Ruby. Yes you can write very elegant PHP code, but when it comes to maintain this code (more then that if the code base is big), it is a painful job. With Ruby you get the same power of PHP, but even more you get full OOP (not just baby OOP style that PHP supports), easier maintain code for extra large projects. About scaling of Rails, it was in the past, nowadays Rails scales even better then Zend Framework.
    PHP will remain on its place on the market, on the other side, Ruby (especially with Rails framework) will grow and grow even higher then PHP.
    Ruby is the future of open source dynamic web development.

    14. Jesse Skinner at 3:53pm on October 12, 2009

    @Vitaly - Thanks for the very intriguing comment. It has given me a lot to think about.

    I think I will still favour PHP for lightweight and simple projects, but you're very correct that the scalability and deployment issues of the past are gone, and we should now compare  languages and frameworks alone. I think you may have led me to take a fresh look at Ruby and RoR again.

    15. Mahdi at 8:10pm on October 17, 2009

    Well, although I am not a professional programmer, but I can get my way around and design websites in RoR and php. I don't know asp.net and not much interested in asp, because I love the open source and free software world. So no idea about asp.net, but about RoR and php:
    I love RoR because of its code, its architecture, its simpleness. And I believe generally it can be used both for small and huge sites. and of course generally web development with Rails is agile. But sometimes in special cases, it is really really annoying, you have to work for hours or even days to solve a problem and at last you have to solve it with a solution which is not well-fromed from progamming point of view. When I start RoR I know what should I do and where should I do something. But after a few works, sometimes I am lost in different pages and models and views and controllers and layouts and ...  that I really don't know where should I do the code to do sth. The php generally needs more time, more accuracy, and I feel I am mixed up at first that what i should do now. But after I start the project, I feel everything is straight forward, I know where should i put a code segment. Although RoR is integrated with mongrel or webrick and sqlite and it makes development easier, but It makes deployment hard. Everytime I start a RoR project I worry about the final, the deployment, especially lack of RoR hosts servers in comparison to php and also the versions as each rails version has huge changes to its previous one. But when I start coding php i completely feel free about the last. apache,mysql and php itself, on every hosts and servers, availabe.

    16. Haydies at 7:49am on February 3, 2010

    I have worked on many very large web sites writen in PHP, it not a language problem that makes bad php sites. However my one and only expirance of ruby was terrible and resulted in its proponents being fired, and their job being done in .net.

    Ruby is fine as long as you want to do what ruby says. But PHP does what ever you want.

    If you can't code, use ruby. If you can't cope with a little SQL use ruby (it's CRUD).... but if to say php syntax is clunky? well, blame that on C, its only worlds most popular language, and so php has a C style syntax.

    PHP code is totally maintainable if it's writen to be so. It never a problem with my work because that is rule number one. Do it once, and do it right. If you hacking code thats dirty in any language your a fool. It will come back to bite you in the a***

    0ver 20 years of programming in OO, and I say PHP is the best development language for the web.

    Oh, and these days a lot of its done with frameworks. Druple and such.

    17. Jabari at 7:46am on February 17, 2010

    1) I don't know why people keep comparing the two unfairly...

    RoR SHOULD be easier to maintain, as it is a language & framework together.  That is the whole purpose of the MVC way.  PHP is a language by itself.  There is absolutely no framework included.

    2) It's about the PROGRAMMER...

    No framework means YOU AS A PROGRAMMER control how simple/complex/scalable/manageable your code is.  You can use readily available MVC frameworks such as Cake PHP and Zend, you can roll out your own (my personal favorite), or you can write ultra simple scripts with no framework what-so-ever.  PHP allows power & flexibility IF AND ONLY IF you are a good programmer.If you have fed the PHP engine a poor code diet in the past and it began eating your server as a supplement because of it, you need to STOP blaming PHP and start improving your programming skills.  Sometimes you have to bite the bullet and realize that you practiced bad programming habits (I've been VERY guilty of this before myself).

    3) RoR performance is sub-par to PHP and ASP.NET

    You also have to bit the bullet on performance.  I know RoR proponents say that those issues are "in the past", but they aren't.  Someone mentioned Twitter's RoR issues in a comment here back in 2007.  It's three years later and you can almost set your watch by when Twitter will go down.  RoR is great for light to mid-level traffic, but it has entirely too much overhead to stay stable when traffic is really heavy unless you have a ridiculous hardware budget (and even if you did, why spend the money there if you didn't have to?).  The number of unnecessary DB calls for simple tasks by itself is straining.  I won't even get into helpers and GC.  I'm not saying RoR is bad per say.  It simply has a cost for fast development, and that cost is performance.  It's a great tool if you need to roll out a quick app/site that will get mid level traffic, but it's not yet an industrial strength, iron clad, steel belted radial, up and running with five 9's of availability solution.

    18. jeremiah at 6:59am on April 4, 2010

    I've managed to learn php all by myself by editing a complex php script(that's how it began) - and I couldn't done that without a php ide - i used nusphere for that - Now I think at myself as a "parkour programmer" because I don't want/need to write a robust code but I just want to get from point A to point B as fast as possible. I need a IDE because that's just how I learn things ... I put my code into a IDE and then step by step I watch what's happening and have my google search close by. Finally my question: What's the best Ruby  on Rails IDE for us beginers to start.

    19. nini at 11:21pm on May 6, 2010

    good

    20. Prashanth at 12:58am on May 24, 2010

    Good conversations

    21. Evin Weissenberg at 11:38am on April 27, 2011

    Your statement is false when you say that the ONLY way to build so called complex sites is using an MVC structure...

    How long have you been coding for? 6 months?

    22. Kyle P at 9:39am on July 19, 2011

    I have been developing web applications with PHP for a few years now and have only recently thought of looking into RoR. I've found these posts to be very informing. Thank you.

    23. agus @ ROR Developer at 10:10pm on January 9, 2012

    You CAN compare Rails with PHP. They are both tools (to use a broader term) to develop web applications. What the commercial is saying is that developing with Rails can save you a lot of headaches PHP would cause. There is nothing wrong with that, considering that a great number of websites/web applications used to be developed with PHP alone, without any additional frameworks.

    So please, stop saying the same thing over and over again.

    Commenting is now closed. Come find me on Twitter.