5/16/2008

PHP, First Impressions

It has been 3 months now since I started learning PHP, I have spent lots of time fixing an existing site and reading over the good and bad of the available open source PHP projects.

I would describe PHP as a function based language with object oriented dreams. PHP lives in the between world where functions rule and programmers try to work out how to make use of its new OO features.

These OO features are new and many are missing key functionality so this has to be looked at as the evolution of a language that isn't quite there yet. It has the functions to get anything done, it doesn't have the class libraries to get much done.

I am not saying you shouldn't use PHP. This is a versatile language that can be made to describe some advanced language constructs.

It is widely regarded as a slow language that scales well. Not an oxymoron when you consider performance a mixture of response time and throughput.

One thing to get used to with PHP is typing. Everything you want to do will take more characters than java, c# and especially ruby. Every method is a minimum of 19, every property reference roles in at 8 and I can assure you, we programmers do that a lot.

I spend my days developing an class model to support my web project. Some classes support the business functions I need and others just wrap the plethora of php function calls that perform the low level work I need.

Architecturally PHP offers some interesting problems. It relies a great deal of the tuning of the environment that it runs in but from a code design perspective you have to look at the transaction path as a primary and inevitable cost. In java you might start with a simple transaction path through your product layers with the realization that you can cache strategic parts as you advance your performance footprint.

In PHP there is no "cross transaction" static. So every PHP file is parsed and executed for every request. Now PHP does this pretty fast but the more you add into the transaction stream the slower things will go.

Performance is approached at the environment and code optimization level. You tune apache and add in PHP JITs to make the code run faster but you can't do much to dynamically improve transaction path across requests.

The local user group, OINKPUG, is an excellent resource full of great PHP programmers always ready to help.

All in all, I am enjoying PHP and look forward to continuing to twist to my will.

3 comments:

Unknown said...

Good timing Ed, I was thinking about asking you the php development has been going.

I am curious - are you using any IDE in particular? I was reading about Zend Studio for Eclipse.

Thanks for the update!

hellogerard said...

I don't disagree with anything you say here.

In particular, I like these statements very much:

"I would describe PHP as a function based language with object oriented dreams... This is a versatile language that can be made to describe some advanced language constructs."

My current opinion of PHP is pretty much the same as what you said. I could create a huge website with nothing but procedural files filled with conditional statements and code mixed with HTML. I could create the same website in a fancy PHP MVC, object-modeled architecture too. The many ways to do one thing reminds me of Perl, which isn't a good thing. And PHP keeps growing. Maybe all languages are like that.

In PHP, it seems like everyone goes through the course from the easy crap to more sophisticated solutions (except for you maybe!). But in other languages, there isn't as much rope to hang yourself with, and the "golden path" is much more enforced, which can be nice.

I'd *like* to get into other languages more, but at this point, when confronted with a problem, the PHP solution comes to mind almost instantly, so in the interest of time I always go with it.

Regarding transactional requests, PHP was of course designed to be very fast at "shared nothing". I've been toying with an idea of storing objects in a global cache like memcached that might help that.

Edward Sumerfield said...

steveg I am using Eclipse with the PHPClipse (http://www.phpeclipse.de) plugin. Though I heard at Oinkpug last night that the Eclipse PDT (PHP Developers Toolkit) is quite good now (http://www.eclipse.org/pdt).