8 ms·
How I Build PHP Applications
- ldite 16y agoSummary; I don't like frameworks, so I rolled my own framework.
- balac 16y agoSummary: I didn't understand how to use a framework, so I rolled my own one that doesn't really do much.
- itsyou 16y agoMiss the point more?
- steveklabnik 16y agoI don't think he's really missing the point. This guy complains that he's always re-implementing the stuff that frameworks don't provide... but all of the stuff he talks about is just the basic features that every framework provides. He'd still have to develop those features on top of his homegrown framework.
- pstevensza 16y agoWhy carry around the weight of a framework if you're happier doing things this way? Insofar as an idea on putting together a sane PHP project built from the ground up, I think it's a good article.
- zalew 16y agoWhat 'weight'? A good framework doesn't stand in your way, it lets u focus on business logic solutions instead of repeatable tasks. Sooner or later he'll discover that he's getting to the point where he needs to provide solutions for problems that are already solved by a variety of well-maintained toolsets, and the lack of abstraction will make his projects hard to develop further.
- sorbits 16y agoI think it is more accurate to say he wrote his own library. These terms are not well defined (AFAIK) but often a framework implies that you have something “already running” which you customize by providing callbacks, delegates, and similar. With a library you have a set of reusable functions and data types (classes). I think an Apple engineer referred to frameworks as “the hollywood model: don’t call us, we call you”. For PHP programmers that dislike the framework model, have a look at http://flourishlib.com/ http://flourishlib.com/ — been mentioned on HN before but I hadn’t seen it before this week. In philosophy this is exactly how I prefer a good library of re-usable code: lots of self-contained functions and data structures which each solve a problem, and you decide when to use what.
- wanderr 16y agoYes, I think a huge part of the problem wih frameworks for a lot of programmers, myself included, is a lack of control. The framework takes control and you have a certain set of ways to modify its behavior. If what you need to do isn't something the framework designers had in mind, you may have to hack the framework. Even if it is something they had in mind, it can be much slower to hunt around and find the 'right' way to tell the framework to stop doing this automatic thing and do this other thing instead. It is often much faster for an experienced and skilled developer to write something that just does what they need to begin with. Libraries, OTOH, don't presume anything about taking control. You're still the driver, they just have a lot of things that can make your life easier if you choose to use them.
- armandososa 16y agoSummary: I don't like frameworks, so I traveled back in time and created CakePHP 0.9. Really, I'm sure no one remembers CakePHP back then (they had not the pretty site yet) but was pretty much this.
- keltex 16y agoA friend of mine does software consulting for medical groups. He rolled his own framework which is a combination of SQL Server and ASP classic. The funny thing is that it was the SQL Server stored procedures that generated the HTML, not ASP. I couldn't figure out if it was genius or insane.
- blaix 16y agoIt was insane.
- wizard_2 16y agoI like this kind of post, but its not a topic I care too much about anymore. Like the author php pays my bills too, and most of my work is done alone. He doesn't like frameworks for reasons I don't like frameworks, abstractions are leaky. I still use frameworks because I'd rather have a team of people work on some of core features I use (orm, url routing, view engines) then just myself. I've also found that some php frameworks's abstractions are leakier then they should be (cakephp, and symphony come to mind). The reason I don't care is that I'm moving on, and now php seems like such a mess. I used to not mind the arrays, the lack of proper objects. The oddly named functions. The years of backwards compatibility. I've been learning python over the past few weeks and using it for a few projects and I'm in love. Next up is probably Ruby but it looks like perl to me so I'm in no rush. I feel like python is a better language because I'm better. Exposing yourself to different ways of thinking lets you pick up methods that work better then you knew before. I didn't even know what I was missing.
- jacquesm 16y agoDo you use a framework for python or do you code it all from scratch ?
- wizard_2 16y agoI've mostly been using django which is wonderful (even more so if you do things their way). The thing I love most about django is their orm, it makes cakephp's orm feel like a toy. I haven't yet used pylons, but I'm thinking that it would be good for me to learn another orm and it offers full support for a few. The reason I picked Django was the "apps". App's are python modules that tie into your project and provide functionality of some sort. The two ones off the top of my head are the "admin" app, which is frankly amazing, and the comments app which is a good example of what most apps are. An app that handles posting of comments and attaching them to any other kind of model. Django's history is in publishing and it shows. One app I'm making is for a real estate firm, I'm using Sorl Thumbnail, django-googleappsauth, and the admin app to take care of posting photos, having a single login with their mail (google apps) and a nice featured interface for the agents. Django's a great fit. The other app is an internal order tracking system that has to check against edi files and all sorts of other gotchas. It's got to do operations on millions of rows and lookups from multiple databases. Python has no trouble with most of this, but django's apps and orm doesn't exactly fit with the bulk of the operations. I do however use the django user system and fairly easily tied it into an active directory auth backend. The Admin app isn't useful at all for most of the interfaces, but the form classes and view layer (usually called the controler in most mvc's) let me do what I need to.
- iaskwhy 16y agoI didn't know Ellis Lab had codeignitor.com pointing to codeigniter.com! From the article, I can only say the author didn't try CodeIgniter for a couple of hours otherwise he would know you are free to do pretty much whatever you want with the framework. I do use CodeIgniter for all my projects and I do write my own queries most of the time (I'm a query performance geek). I think the only thing you are not free to run away from is controllers but that's the basic structure of a (MV)C framework.
- drm237 16y agoIt's also one of the smaller frameworks compared to Cake, Symphony, and the other rails-on-php frameworks so I'm not really sure why the author singles it out as "large" framework.
- SlyShy 16y agoOT: I wish some people would add a left-margin to their texts.
- chime 16y agoI use something similar to his /index.php solution and it has worked great for me. My .htaccess ends with: ### Disable direct access to *.php except main index.php RewriteCond %{REQUEST_URI} \.php RewriteCond %{REQUEST_URI} !^/index.php RewriteRule ^(.*)$ /index.php [L,R] ### Run the main /index.php controller file RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php [L] In my index.php, I include my common functions and then call the appropriate file/class depending on the hostname and url. I don't know why he dirties with index.php call with: path=$1&%{QUERY_STIRNG} - that information is available in $_SERVER[] variable. What this overall approach really means is that there is a single entry point for every single thing in my app. I can manage sessions, db, custom functions, login/admin, handle apis etc. through one piece of code that is (selectively) executed for every single request. I can also shutdown the entire site and all the operations with a "sorry we're down for maintenance" if I need to. I don't even store my php files in /www folder so you can't even access them directly. This approach can easily handle my traffic - 10k uniques/day on average, 100k/day on special events.
- tszming 16y agoSee also, The no-framework PHP MVC framework (by Rasmus, the creator of PHP) http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC...
- ido 16y agoI'm surprised he argues that PHP will land you well paying jobs - in my experience java and c# jobs (especially ones with the word "enterprise" in the description) pay far better than php (with c,c++ and most other popular languages like python and ruby somewhere in the middle).
- patio11 16y agoThe big secret is that programmers make more money when they stop pitching themselves as programmers and start pitching themselves as skilled professionals who make their firms millions using a variety of tools, including code (when appropriate). OK, it isn't much of a secret. I wince every time I hear someone describe himself as a "PHP coder" in mixed company (i.e. in front of folks with hiring authority rather than "just us geeks"). Buy a box of cereal and you get two of those for free.
- jqueryin 16y agoSoooo what's your job title? It sounds like you've sugar coated the hell out of it.
- hnal943 16y agoHis job title is "Founder."
- steveklabnik 16y agoIt's not sugar coating. That has the implication that he's lying; but programmers (at least good ones) do all of that. We create an incredible amount of value, and it's a disservice to ourselves to forget that.
- rmc 16y agoI believe it's "The Boss"
- nir 16y agoHow would you suggest he present himself? (Not sure about devs coming with cereal boxes just yet, btw... The want ads I see still ask for "PHP Coder" and offer six figure salaries for good ones)
- robryan 16y agoSimilarly to the author I don't use any frameworks, well except JQuery for front end and XTemplate for templates. Main reason being when I'm a lone developer I prefer having stuff I'm comfortable with and understand back to front. I'm sure I could get this from a good framework that doesn't have a lot of linking between parts but I'll admit I haven't put a lot of time in to try and find this. The more I learn about PHP internals the less confidence I have in the language. The main things holding me to the language is comfortableness with the syntax- been using it for years can code very quickly in it, understand a lot of the functions and extensions I would want to use normally and a good feel for what will run fast and what won't. The being said I would like to learn a ruby/python like language when I get the chance, I have previously done web stuff in .NET and Java but much prefer PHP over those for my uses.
- steveklabnik 16y agoIf you do get the chance, check out Ruby and Sinatra. The whole source is only roughly 2000 lines of code, but it gives you just a very minimal level of abstraction over HTTP. Here's "hello world" in Sinatra: require ‘rubygems’ require ’sinatra’ get ‘/hi’ do “Hello World!” end ... That's it. It's cool stuff.
- mixmax 16y agoAnd here it is in PHP: echo "Hello world"; One line. Just saying....
- cmelbye 16y agoExcept not at all. Your example doesn't handle a clean URL like "/hi" (it would be something like "/hi.php" at best in PHP). Furthermore, it doesn't force the GET http request type, which is a major part of the Sinatra microframework. I can setup a Ruby script that outputs "Hello World", but that would miss the point entirely. EDIT: Also, the original ruby example could be condensed to one line as well: get "/hi" { "Hello world" } Run with ruby -rsinatra script.rb
- 16y ago
- olliesaunders 16y agoI'm having problems viewing the page but this works: http://74.125.77.132/search?q=cache:s9EotdZKkwYJ:ericharrison.info/2010/04/21/how-i-build-php-applications/+http://ericharrison.info/2010/04/21/how-i-build-php-applications/&hl=en&strip=1 http://74.125.77.132/search?q=cache:s9EotdZKkwYJ:ericharriso...
- jqueryin 16y agoHow he builds web applications... to not withstand traffic when it hits the main page of YC.
- rubinelli 16y agoMy guess is shared host + uncached WordPress. It works pretty well up to 5 visitors/day -- which, sadly enough, makes it a great 90% solution.
- kunley 16y agoFunny. My friend was much like that guy (also with some framework past, he did some extensions to the eZ for instance) but switched to Ruby recently and says: no intention to go back. First he just started to generate pages using erb, much like you would craft quick'n'dirty php pages getting stuff from the db, but with erb. He said the clean syntax and sane libraries were refreshing. Then he discovered Merb and started to tinker with it. He didn't want to check Rails as it seemed "too high level, too automagic", good for him. Then, when I mentioned Rack, he tried it and fell in love with Sinatra (no pun intended). Now he says he's several times more productive than with PHP, doesn't go insane, doesn't have to learn big monstrous framework (that was the reason he sticked to PHP in the first place), can invent and use his low-level hacks on a http conversation. So: what he did quick'n'dirty in PHP he now does quicker'n'cleaner in Ruby, still being low-level as he likes it. The catch is that no one has never evangelized Ruby to him. He just tried it out of his own curiosity.
- arnorhs 16y agoThe author seems to not make a distinction between a web application of some sort and then a website. If he's making a website for a client, I really doubt that he likes to write all the code to edit pages, blog, update images etc himself for each project. It's much easier to base your project on a preexisting solution like WP, joomla, etc. However, if he's making a web application, using joomla/WP is a complete nonsense, so using a framework like Code Igniter is perfect. He doesn't have to use the ORM if he doesn't want to, he doesn't have to use the forking if he doesn't have to. Code Igniter is super lightweight. On PHP's faults: When you've been working with PHP for a long time, all those issues mostly become non-issues, documentation reference lookup using http://php.net/<searchterm> http://php.net/<searchterm> is super sweet, the arrays with all the array functions make arrays incredibly powerful, you can turn off all the automatic sanitizing code if you dont' want it, etc... We've all seen UGLY php code, but that's just because the barrier to entry into becoming a PHP developer is so small, so there's a lot of bad coders out there. But if you do things right, PHP development is very stable, you can do incredible amounts of work in a short period of time and the amount of information and pre-built code out there is vast.
- phatbyte 16y agoI wrote an article that tells you why this might be a good choice. http://news.ycombinator.com/item?id=1288416 http://news.ycombinator.com/item?id=1288416
- ck2 16y agohttp://google.com/search?q=cache:ericharrison.info/2010/04/21/how-i-build-php-applications/&strip=1 http://google.com/search?q=cache:ericharrison.info/2010/04/2...