9 ms·
Going Back to PHP
- chasingsparks 17y agoI got 9 up votes for my comment on PHP in http://news.ycombinator.com/item?id=903402 http://news.ycombinator.com/item?id=903402 so I wrote this blog entry while at work. I have a feeling the post makes me sound like a douche. We'll see.
- tptacek 17y agoYou could have deployed code using SCP with Passenger, which is basically Ruby deployed PHP-style and is basically the emerging standard for how Rails apps are deployed. So immediacy seems like a weird reason to take such a step back on languages. But I mean, do whatever makes sense for you. PHP apps are good for business for us. =)
- chasingsparks 17y agoSee the footnote. I mentioned passenger.
- tptacek 17y agoYou didn't say anything about it, only that "it's a game-changer for Rails application deployment" and that PHP is better, for no reason you can articulate. I don't care.
- ionfish 17y agoOr better yet, via git push and a post-receive hook to touch tmp/restart.txt...
- steveklabnik 17y agoOr better yet, using Capistrano to do that and more.
- tptacek 17y agoThings like Capistrano are the reason this person gave up Rails for PHP, and I don't really blame them.
- steveklabnik 17y agoWhy? I mean, for a very basic setup, you just run 'capify .', and then change some passwords, and you're good to go. It doesn't even really take any configuring. Here's the thing: good engineering means that you should automate as much as possible. That way, everything is consitant. One command deployment is amazing, regardless of your technology stack.
- tptacek 17y agoIt's more complicated than just scp'ing files over. That's all I have to say. It's fine to say that it's also better engineering, but that doesn't address the original article. Ruby is also a better engineered language than PHP in a lot of ways.
- steveklabnik 17y ago'cap deploy' is easier than 'scp here there'.
- tptacek 17y ago[9:28pm:/playbook] DIVISION:tqbf [0:279]% cap deploy the task `deploy' does not exist
- phaylon 17y agoIn general I can't disagree. If it makes sense, use it. What always struck me as odd though is the heavy focus on application code deployment. I mostly work on larger projects, so application updates are usually simply a pull from the repository. It is usually a bigger hassle to get a smooth transition of the database schema, file-system storage or anything else that holds data.
- chasingsparks 17y agoThat may be true. I have not seen what Cake offers in that respect. For the few rails projects I developed, I used capistrano but for small projects this felt unrewarding. Tangentially (to git pulls), I did notice that PHP developers favor SVN to git, which I don't like as much.
- vital101 17y ago"I did notice that PHP developers favor SVN to git..." I can attest to this. I spend a lot of time working with PHP with a lot of different people, and almost every single one of them uses SVN for deployment. I'm not sure if this good practice or not, but it's just so convenient.
- jmtame 17y agoi can only hope this post doesn't degrade into a troll war about why ruby is better than php or vice versa... i've used both, they both work, they're both fine. can't we leave it at that? =]
- neilk 17y agoPHP has a lot of virtues. It's fast. It has libraries for almost everything a web programmer needs. Deployment is trivial with SCP and with rsync scales to hundreds of machines easily, with barely more infrastructure than a shell script. Even its supposed deficits are advantages sometimes. PHP stops you from a lot of temptations to go non-REST. Anyone who's seen a Java project where the web server is spawning multiple threads per request can understand. It just gets incredibly annoying when you try to do anything complex with programming logic. Due to its rather low ceiling of abstraction, PHP encourages you to cut and paste rather than refactor. Again, not actually a problem for many, until you get to a very advanced stage (say three years) and how many projects even last that long?
- lamby 17y agoWait, how do you deploy with with scp? What happens when you drop a file locally?
- tibbon 17y agoHe's saying that all you have to do is post the file on a webserver with PHP installed and it should work. No compiling. No raking. No installing Passenger, Rack, etc... I'm a Ruby guy, but I do recognize that PHP deployment is generally fast, smooth and easy.
- lamby 17y agoI understand the above, I was asking something else.
- aaronblohowiak 17y agoYour app machine pulls the new version from the source machine via scp, then changes a symlink. like a poor man's rsync --backup
- tptacek 17y agoThat exact same workflow exists for Passenger. I'm not even sure you can install Rails without Rack anymore. And installing and deploying a fresh Passenger install is easier than deploying a second app on a Mongrel/Apache cluster; it is very, very easy.
- techiferous 17y agoRails + Heroku is deployment heaven. It's even easier than scp.
- releasedatez 17y agoYes, +1 for that. "git push heroku master"
- jshen 17y agoand expensive
- techiferous 17y agoActually, this is one thing that I really love about Heroku. They will host apps for free. I put my http://2rgb.com http://2rgb.com there and am not paying a cent. For a serious app, I'll have to start paying, but the prices seem worth it to me because they're saving me a lot of time. Maybe it's expensive compared to other hosts; that I don't know.
- jshen 17y agothe free account only allows 5MB of storage. I can't do much of anything with that. From there it gets expensive fast if you run multiple sites. It might be a different equation for a single site.
- jrockway 17y agoDo serious PHP developers use PHP's built-in template language? Yahoo and Facebook don't. PHP is also not tuned to some fitness function; it tunes its users. In exchange for not having to understand abstraction or OO, you get to learn the wierd quirks of thousands of inconsistently-named functions that live in a shared global environment. Sure, the number of "concepts" you have to know is low (no closures, no MOP, no lexical scope, ...), but the number of inane details you have to know is high. PHP shows that people would rather understand the exact details of arguments to a function instead of understanding abstraction and metaprogramming. (Similarly, people like to cram for exams without really understand the subject matter.) That is fine, but unless you are "people in general", you are missing out on a lot by "choosing" PHP. (Deployment is always a big issue. Do you really want to market your app to people that can't even run a package manager, "cpan" or equivalent, and so on? I find Perl perfectly easy to deploy. If I can't "apt-get install" the app, I type "cpan AppName", wait a while, and my app works. Additionally, users that find deployment too hard unless it's "untar this and click pictures" are going to require a lot of support but aren't going to contribute a lot of code back to you. So maybe this isn't the best optimization to make. Finally, why not JSP for this? Startup Tomcat, edit code in a web page, and boom, your "app" works. It ain't pretty, but it's better than PHP. Tomcat is no harder to setup than Apache + mod_php either.)
- philfreo 17y ago> "PHP shows that people would rather understand the exact details of arguments to a function instead of..." I disagree. While yes, the function names and parameters are not always consistent and easy to remember, the point is they don't have to be, because it takes very little time to type "php.net/thefunctionorclosetoit" into a browser and quickly reference whatever you need. Add a smart IDE that gives parameter hinting into the mix and you don't even need to do that most of the time.
- Zarathu 17y agoEh. I decided to read the post because of how outrageous the title seemed, but I can't say I really agree with the gist of what you're saying. I don't really understand why you'd prefer to deploy over SCP, either. You know what's really trivial? "cap deploy" As far as speed goes, I think of Ruby as some sort of investment, in that I believe Ruby's 2.0 era will surpass PHP, and perhaps come close to Python.
- igouy 17y ago> As far as speed goes... But will any of them catch up to JavaScript :-)
- adriand 17y agoWhen I was first learning Ruby on Rails as a proficient PHP programmer, the company I worked for landed a largish (for us at the time, given there were only two programmers in the place back then) contract for a web application. Since I was just learning Rails, and I needed to be highly productive on the project, I recommended that we use CakePHP so I could use my PHP skills. I figured my co-programmer, who loved Rails, would acquiesce due to the presence (at least) of an MVC framework, and I was right. I've regretted that decision many times. Not all MVC frameworks are created equal, and I can say from painful experience that Rails is far superior to CakePHP. We got the job done, and I may have been right that I was more productive in PHP back then than I was in Ruby. But three years later, it is far more difficult to get things done on this web app than if it were built on Rails. I'm not one to engage in language wars, and I still enjoy coding in PHP. But if you want a great framework, I'm still not sure you can beat Rails, and I really don't think there's anything in the PHP world that can.
- trevelyan 17y agoJust out of curiosity, what problems did you run into specifically? I adopted CakePHP for similar reasons and haven't run into any issues that have made me regret it, although I did leave standard development practice for a few reasons that have made caching a bit more difficult than otherwise.
- adriand 17y agoSorry, I tend not to notice when people respond to my comments, it'd be great if this site had an easier way of letting you know when people do (maybe I'm just not aware of it?) Anyway, the main issues I ran into were all related to database queries. This application was not a standard CRUD-style app at all, it has a lot of pretty complex queries for building reports. I found the way that CakePHP deals with joins and associations really clunky and hard to use compared to Rails' ActiveRecord. I'd often have to write the raw queries and try to shoehorn them into CakePHP's ORM objects. I just found myself frequently frustrated with the way it was working. It's been too long since I really worked on it for me to be able to give much more detail than that (also, it probably has improved a lot since then too). That said, using it as a web framework still made coding the app a heck of a lot easier than it would have been without it. Also, I found that it really improved my PHP skills, I picked up a ton of good stuff from using it.
- petercooper 17y agoConversely, PHP has one several advantages over Rails. Most notably, immediacy. Deployment via SCP is very satisfying. Though not as satisfying as using source control and having a one command "deploy" that's just as quick as SCPing a bunch of files.. I can deploy - to production - local builds of my Ruby projects in seconds. There are no significant advantages to using PHP or disadvantages to using Ruby or Rails presented in that blog post, even though it tries to make it seem that way. (And on the library complaint, the Ruby libraries that came along for things like S3 and EC2 are better than the official ones by a long shot.) Despite that, different strokes for different folks. Use what works for you and all that!
- steveklabnik 17y agoI come off like a Capistrano fanboy in this thread, but I guess that I kind of am. I only ever used the SCP method when I did PHP stuff, but the projects were never anything that big. Now that I do Rails all the time, having a tool like Capistrano is amazing. 'cap deploy' copies my code, changes the symlink, updates my database schema, notifies my error reporting, restarts my webserver, and cooks me dinner. Okay, I exaggerate. But seriously. Automation! It's awesome.
- petercooper 17y agoIt is! And even if you just jury rig it! Several of my projects have a deploy script that's just a bash one liner that does a git push and does a git pull and touches a restart file on the server :-)
- steveklabnik 17y agoAnother advantage of this is that it makes you actually commit to your repository, if you're bad at that kind of thing.
- chasingsparks 17y agoThis post is meta-interesting for me. I did not expect it to elicit 4,000+ unique visits. I almost want to put an: Update: PHP S%cks! at the top of the blog post just for fun (I wont).
- jrockway 17y agoYour post appeals to two audiences; the blub/PHP programmer that reads your post to justify his own tastes, and the OMG Ruby Is So Awesome programmer, who wants to read your post to tell you how dumb you are. I wrote about Java once on my blog. Never again. That is a crazy language community.
- chasingsparks 17y agoSadly, I think your summation is accurate.
- neovive 17y agoAfter reading up on the powerful SPL classes included with PHP5 and developing on top of the very well-coded KohanaPHP framework, PHP development has become very productive lately. Although, I prefer Python's syntax, the deployment speed of PHP is very hard to match. The inconsistent function library definitely gets annoying, but I guess that's why PHP has such excellent documentation. Using Eclipse PDT code hinting also mitigates the API annoyances.
- strlen 17y agoPHP is one language, I am absolutely not willing to (primarily) develop in. I've left a PHP-only job almost entirely over the matter of language choice (there PHP was used for everything. My worst decision there was -- after getting a Hadoop cluster going -- showing the team how to do Map/Reduce in PHP via the streaming API). I've never felt a strong repulsion to any language like I do with PHP and I wonder why. I think at the core of are these facts: it's optimized for web development, doing anything complex or CS/math intensive (developing algorithms, doing off line computation, systems programming) is sometimes possible, but always painful. I've played with PHP3 before college and other than what I've learned in a databases course, very little what I've learned in a university seems to be applicable to routine PHP programming. It doesn't feel like actual development. Ironically, PHP seems to work very well in conjunction with more powerful languages: Yahoo, Facebook and others are built with PHP as essentially a template layer, with Java/C++/Erlang/Perl/Python on the backend. Perhaps the fact that coding PHP doesn't feel like software engineering is it's greatest asset. It's a language that a web developer can immediately be productive in. Yet it also exposes what is often tediousness and triviality of most web development. I remember first playing with emacs, SLIME, cl-sql, mod_lisp and UCW: while I was writing a web application (something PHP is well suited for), I felt I was excercising my brain a great deal more. To a lesser extent it felt true with Python/CherryPy and Perl/mod_perl. Perhaps what makes PHP successful at Yahoo and Facebook is that they're serious, well-funded technology companies who are able to attract talented developers (who can take advantage of PHP's easy interoperability with C). An early stage start-up choosing PHP seems to almost doom itself by attracting a crowd that treats PHP as Blub (rather than as a sometimes appropriate tool), or in less refined terms "script kiddies".
- tybris 17y agoUsing PHP hits back at you after a few years when you find out all its libraries are slowly rotting, revealing fundamental security flaws that will give you unimaginable headaches. These days I select my languages purely by programmer competence.
- jrockway 17y agoSo true. PHP library implementers seem to love making everything a strange corner case instead of taking a step back and picking a better abstraction. It is amazing how easy it is to write code that works for all possible inputs when you pick the right abstraction, and it's amazing how downright difficult it is when you pick the wrong one. PHP libraries function accordingly.
- antirez 17y agoI use Ruby and I love this language, truly. I wrote my framework, play with Sinatra, and so on, like you. But we are in hacker news and are in some way a closed ring of people a bit smarter than the average programmer. Then there is the mass of programmers that could witch from PHP to something better. All they want is a mod_please_make_ruby_simple that is, like mod_php but for Ruby. You install it on Apache, and all the pages called .rhtml will get executed with the trick of things outside <? ?> being translated into echos. This module should also provide, automagically and built-in, support for all the obvious stuff like file uploads, MySQL bindings and so on. I understand that PHP got this right for the masses, but can't understand why no one is trying to do it the right way for other much more powerful and elegant dynamic languages.
- jrockway 17y agoBecause those of us that know how to implement that sort of system have no need for it. There are thousands of things I want to implement; making something I'll never use is not one of those.
- richz 17y agoCould someone please provide a link as to how Facebook and/or Yahoo use PHP with "templates"? I want to create "yet another" social networking site for a niche market, and am trying to figure out what technology would work best for this space. I've been using asp.net for the last several years, and used to code in mod_perl, java, etc. But, I don't have any experience with the newer open source languages. I want to pick what's a good fit (even if I have to learn a new language). I know these are just basic details, but would greatly appreciate any feedback. Thanks! (long-time lurker, first-timer poster)