Amirouche Douda
Amirouche Douda

Reputation: 1564

PHP developer looking for solutions equivalent to Java EE architecture

I am a PHP developer, I read about Java EE technologies and I want to implement such technologies( n-tier, EJB, JPA...) with PHP and all what coming with (MySQL, Apache...).

Upvotes: 6

Views: 6592

Answers (2)

DigitalDave1
DigitalDave1

Reputation: 27

Your question is an insightful one. That's because as your enterprise becomes more successful, it will have to scale up to support the load of more traffic. So you will have to separate your PHP code into layers that run on separate tiers (either separate servers or separate Virtual Machines like with Xen.)

For example, I designed a system last year implemented in PHP on 10 Linux OpenSUSE servers running about 25 Xen Virtual Machines (VMs.) Some of the VM's were load balancers, some were front end tiers, some were middle tiers and some were back-end tiers, some contained MySQL databases, and we had a couple of dedicated servers that were RAID arrays for user file storage. We created NFS mounts as necessary to save/read files to/from the RAID array.

We grouped the tiers into three related groups, so we could have independent test sites for QA, Staging (User Acceptance) and Production.

So our PHP software was separated into loosely-coupled layers as follows:

FRONT-END TIER (VMs)

  • Application Layer (port 80) -- including AJAX responses, validation code, navigation, etc.
  • Admin layer (port 443) -- including Admin Dashboard with access to system metrics and Unit Test harnesses
  • Service Provider (port 443) -- Secure RESTful Web Services API (with token) to provide services to Partners and others who use the system as a "platform."

MIDDLE TIER (VMs)

  • Business Logic Layer -- calculations specific to the system or business, or the roles and permissions for various use cases
  • Interoperability Layer -- authorizations and posts to Social networks or Partner applications, etc.

BACK-END TIER (VMs)

  • Data Access Layer -- handles SQL queries, inserts, updates, deletes to the database (implemented as Prepared Statements) in a way that can be adapted when the database changes to a different kind...example: from PostgreSQL to MySQL or vice versa. Includes PHP code for backing up and restoring databases.

The idea another respondent brought up of using a Framework for enterprise software seem pretty silly to me. If you are developing a student project or a “proof of concept” on a single server, and if you already are familiar with a framework, it may have its use for rapid prototyping.

But as you see from the above, when you are writing Production-quality code, distributed across multiple tiers, you don't need the crutch of using a Framework.

Where would you put the framework to link into all the places in your code? On every tier? Bad idea. Frameworks include many pages that you may need and you may not need. So they slow down performance, especially when multiplied by every tier on which you must install them.

Equally inefficient would be to create a “layer” just to contain a framework that every other layer would have to call. The benefit of software layers is to be loosely-coupled and independent of other layers, so that when changes occur in one layer, they do not require changes in another layer.

Besides, developers who write Production-quality code don't need to rely on a “swiss-army knife” that Frameworks represent. Such developers are quite capable of writing targeted efficient code and, if necessary, reusing classes in a library they may have developed for previous projects.

Upvotes: 1

Charles
Charles

Reputation: 51411

Don't.

PHP is not Java. Writing PHP code like you'd write Java code is silly and counterproductive. It's very likely to make future maintainers of the code want to hurt you.

Need to persist an object? Use an ORM.

Need a multi-tier architecture? If you design your code with proper separation of concerns, you've already gotten 9/10ths of the way there.

EJBs? Every time I read the Wikipedia article, they're described differently. Reusable components? With a standardized interface for what, distributed applications and data persistence? Useful, yeah, but that's not PHP. ORMs and a a good message/work queue will get the job done.

The bottom line: For the vast majority of PHP scripts, you will not need any "enterprise technologies." If you do, you're doing something wrong: either you've having overarchitected the application, or you've chosen the wrong platform.

Start by picking a modern PHP framework, and build your application from there. If you're coming from Java, then Zend Framework will seem the least foreign. Kohana, Symfony and CodeIgniter are all worthwhile. Avoid Cake for now.

Keep it simple and you can't go wrong.

Upvotes: 12

Related Questions