
How I Build PHP Applications - blister
http://ericharrison.info/2010/04/21/how-i-build-php-applications/
======
wizard_2
I 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.

~~~
dagw
As a python programmer who will probably have to use php on an upcoming
project, I'm wondering if there are any php frameworks you can recommend.

~~~
phatbyte
As ex-PHP programmer converted to Python I will say it will drive you insane
lol. But I've managed to live some of my last PHP projects with with Kohana,
Codeigniter or Zend.

------
robryan
Similarly 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
If 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
And here it is in PHP:

echo "Hello world";

One line. Just saying....

~~~
cmelbye
Except 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_

------
arnorhs
The 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.

------
chime
I 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.

------
ido
I'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
The 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
Soooo what's your job title? It sounds like you've sugar coated the hell out
of it.

~~~
steveklabnik
It'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.

------
ldite
Summary; I don't like frameworks, so I rolled my own framework.

~~~
balac
Summary: I didn't understand how to use a framework, so I rolled my own one
that doesn't really do much.

~~~
pstevensza
Why 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
What '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.

~~~
Pistos2
I never would have dreamed that I'd ever see someone on Hacker News type out
English's second person personal pronoun as "u".

~~~
zalew
Maybe it's got sth to do with that stick up your ass.

------
jqueryin
How he builds web applications... to not withstand traffic when it hits the
main page of YC.

~~~
rubinelli
My 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
Funny. 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.

------
tszming
See also,

The no-framework PHP MVC framework (by Rasmus, the creator of PHP)

[http://toys.lerdorf.com/archives/38-The-no-framework-PHP-
MVC...](http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-
framework.html)

------
iaskwhy
I 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
It'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
OT: I wish some people would add a left-margin to their texts.

------
olliesaunders
I'm having problems viewing the page but this works:
[http://74.125.77.132/search?q=cache:s9EotdZKkwYJ:ericharriso...](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)

------
phatbyte
I wrote an article that tells you why this might be a good choice.
<http://news.ycombinator.com/item?id=1288416>

------
ck2
[http://google.com/search?q=cache:ericharrison.info/2010/04/2...](http://google.com/search?q=cache:ericharrison.info/2010/04/21/how-
i-build-php-applications/&strip=1)

