Download - Enterprise PHP
PHPEE?
The Enterprise PHP
Architecture
John Coggeshall
Zend Technologieshttp://www.zend.com/
Who am I?
● Senior Technical Consultant for Zend
● Author of PHP 5 Unleashed
● Member of Zend Education Advisory
Board
● Maintainer of the Tidy, XMLRPCi, BLENC
extensions for PHP 5
Why am I here?
● Obviously to talk about PHP in the
Enterprise
● But more to the point, where PHP fits in
the Enterprise stack
● Make an attempt to clarify the differences
between PHP 5 / J2EE / .NET
● Drink Beer
Let's start off at the
beginning● A few things I've noticed:
– Defining what exactly is an “Enterprise
Application” is pretty difficult
– People mistake “Enterprise Applications” for
technologies employing things such as
J2EE / .NET / PHP
– People don't identify Enterprise Architectures
as a collection of patterns
What's Enterprise anyway● Can you define “Enterprise” application?
● Scalable
● Large
● Object Oriented
● Oracle-based
● Distributed
● Cash-Cow
● High Availability
● Java Based
● Complex
● Many Users
What's Enterprise anyway● Can you define “Enterprise” application?
● Scalable
● Large
● Object Oriented
● Oracle-based
● Distributed
● Cash-Cow
● High Availability
● Java Based
● Complex
● Many Users
Does any of those
things really define
much of anything to
you?
A Definition I like..ish...From Martin Fowler's “Patterns of
Enterprise Application Architecture”...
● A lot of data
● Persistent data
● Access to Data
Concurrently
● Integration
Devil in the Details● Sounds like a great academic definition
– As always, the implementation is just a little
more complex
● Implied Characteristics
– Scalability
– Availability
– Integrity
From Theory to Practice
● Whatever your definition of Enterprise is,
someone has to actually design an
implementation
● A lot of people mistake implementations
for the definition
– That ends up costing them a lot of money
they might not have otherwise spent.
Enterprise Architectures● Is J2EE an Enterprise Architecture?
● Is .NET an Enterprise Architecture?
● Short answer: Sure
● Longer Answer: They are implementations of
a set of Enterprise Design Patterns
Design Patterns● I'm pretty sure most of us know what
these are. Formally they are defined as:
– A name
– The core of a problem it aims to solve
– The core of the solution to that problem
– The consequences of using that solution
Enterprise Design Patterns
Deal with the details
Enterprise Design Patterns
Deal with the details
- Scalability
- High Availability
- Integrity
Enterprise Design Patterns
● Design Patterns can be applied to more
than just working with OO code
● They can be applied to conceptual
architectures
● Could be implemented by any language
with the aforementioned Enterprise
capabilities
So..?
● J2EE is one application of design patterns
to create an Enterprise Architecture
● Accomplishes most of the goals required
by large-scale Enterprise applications
● But: Generic Problems Lead to Generic
Solutions
Not everything is a nail
● While J2EE succeeds in many ways, it's
really not designed for the “Web
Problem”
● The amount of effort put into even simple
applications is crazy
● There are simpler ways to do this stuff
This is where PHP comes
in● In general, PHP developers can produce
the same web site as a JSP developer in
25-50% less time
● That's not BS either
– PayPal's Sample Integration for PHP took me
about 8 days, the Java guy had been working
on it for about a month.
I'm not saying Java sucks
● It's not that Java/J2EE sucks, PHP is just
better at the web problem
● On the other hand, PHP pretty much
sucks at the Enterprise backend problem
● But with our power's combined....
♥Java
The PHP / Java Bridge● This is pretty sexy:
Using a Screwdriver
● If J2EE is really good at the back-end..
● ... and PHP is really good at the front end
● ... and they can play nice together
● I think you get the picture
● Remember, you can implement the same
design patterns in PHP 5 as you do in
J2EE!
Example PHP/Java
Architecture
For those who are pure
PHP● Of course PHP is more than able to
develop Enterprise applications alone
● Many of the same patterns that apply to
J2EE/.NET will work the same in PHP
● To answer: PHP works great in Enterprise
environments, it just doesn't force you
into a pre-designed mold (good and bad)
PHP Specific Patterns
● There are a lot of Design Patterns which
apply specifically to PHP in Enterprise
Environments
● Esp. when dealing with specific types of
technology (Apache, MySQL, etc).
● Let's check a few of them out
Scaling with MySQL
● I assume you know about MySQL.
– Replication is hot, if you do things right in
PHP
● Scales great until your writes exceed what
can be done on a single machine
– That's almost not true anymore, but for now it
is.
MySQL Architecture
● Often when writing Heavy-hitting PHP
applications the biggest issue is the back-
end database
● When doing a pure PHP implementation,
good MySQL knowledge is important
● Let's look at a great MySQL architectural
pattern
MySQL Replication Pattern
MySQL Replication Pattern
● Works great, but you have to account for
it in your PHP applications
– Application DB abstractions should provide
different facilities at the API level for
reading/writing to the DB and perhaps a third
for FULLTEXT searching
– Even if you don't need it now, a little planning
goes a long way
Leverage mod_rewrite
● If you're web application has a lot of semi-
static content
– Content that could change so it has to be
stored in the DB, but almost never does
● .. And you're running on Apache
● This Design Pattern is killer!
Leverage mod_rewrite
● Most people in PHP would implement a
page like this:
http://www.example.com/show_article.php?id=5
● This would be responsible for generating
the semi-static page HTML for the
browser
Leverage mod_rewrite
● Instead of generating the HTML for the
browser, make this script generate
another PHP script that contains mostly
static content
– Keep things like personalization code, but
make the actual article itself static in the file
– Write the file to disk in a public folder under
document root
Leverage mod_rewrite
● If you put them in this directory
http://www.example.com/articles/5.php
● You can create a mod_rewrite rule such that
http://www.example.com/articles/5.php maps to
http://www.example.com/show_article.php?id=5
● Since show_article.php writes files to articles,
once it's been generated no more DB reads!
Leverage mod_rewrite● Simple and Elegant
Solution
● Allows you to keep
pages “personalized”
● Very easy to Maintain
● Credit goes to Theo
Schlossnagle (?)
Improving PHP
Performance● Improving the
speed of PHP
can be done very
easily using an
opcode cache
So, if you want pure PHP
Or you have an existing
back-end....
PHP is enterprise ready!
Thank you!
Questions? Buy My
Book!