enterprise php

35
PHPEE? The Enterprise PHP Architecture John Coggeshall Zend Technologies http://www.zend.com/

Upload: john-coggeshall

Post on 05-Dec-2014

4.115 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Enterprise PHP

PHPEE?

The Enterprise PHP

Architecture

John Coggeshall

Zend Technologieshttp://www.zend.com/

Page 2: Enterprise PHP

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

Page 3: Enterprise PHP

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

Page 4: Enterprise PHP

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

Page 5: Enterprise PHP

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

Page 6: Enterprise PHP

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?

Page 7: Enterprise PHP

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

Page 8: Enterprise PHP

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

Page 9: Enterprise PHP

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.

Page 10: Enterprise PHP

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

Page 11: Enterprise PHP

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

Page 12: Enterprise PHP

Enterprise Design Patterns

Deal with the details

Enterprise Design Patterns

Deal with the details

- Scalability

- High Availability

- Integrity

Page 13: Enterprise PHP

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

Page 14: Enterprise PHP

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

Page 15: Enterprise PHP

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

Page 16: Enterprise PHP

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.

Page 17: Enterprise PHP

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

Page 18: Enterprise PHP

The PHP / Java Bridge● This is pretty sexy:

Page 19: Enterprise PHP

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!

Page 20: Enterprise PHP

Example PHP/Java

Architecture

Page 21: Enterprise PHP

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)

Page 22: Enterprise PHP

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

Page 23: Enterprise PHP

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.

Page 24: Enterprise PHP

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

Page 25: Enterprise PHP

MySQL Replication Pattern

Page 26: Enterprise PHP

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

Page 27: Enterprise PHP

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!

Page 28: Enterprise PHP

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

Page 29: Enterprise PHP

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

Page 30: Enterprise PHP

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!

Page 31: Enterprise PHP

Leverage mod_rewrite● Simple and Elegant

Solution

● Allows you to keep

pages “personalized”

● Very easy to Maintain

● Credit goes to Theo

Schlossnagle (?)

Page 32: Enterprise PHP

Improving PHP

Performance● Improving the

speed of PHP

can be done very

easily using an

opcode cache

Page 33: Enterprise PHP

So, if you want pure PHP

Page 34: Enterprise PHP

Or you have an existing

back-end....

Page 35: Enterprise PHP

PHP is enterprise ready!

Thank you!

Questions? Buy My

Book!