Three tiered web app setup in PHP?

While I’ve been programming in PHP for years, I’ve never got into actual application architecture and design patterns. I’ve stuck to simple apps and built things using frameworks like Zend Framework or Code Ignitor. I’m trying to learn more about true n-tier setups. I understand the concept and how it works in a language like Java, but am having a hard time understanding the setup from a programming standpoint using PHP. Here’s an example image showing the different tiers:


I get the MVC approach from the programming side but actually separating the functional tiers of the app is where I’m confused. For example, let’s take a shopping cart. You request to view a single item page. The presentation layer would determine your request to view a specific item. It sends a request to the app layer which would in turn retrieve the item information from the database and then return that information to the presentation layer. The presentation layer would then take the data and display it using the proper template(s).

To further this, you would distribute the presentation layer among different web servers. Your app layer could also contain several different servers. If one app server goes down, the requests coming from the presentation layer would just be routed to a different app server.

From the programming standpoint, what’s the best method of accomplishing such a set up. Are you simply building two different “apps” - the application layer app simply has code which accepts requests, pulls data, and returns it. The presentation app would simply issue requests to the application layer and then display content. As in the picture I linked to, the app layer would be some sort of API which accepts requests from the presentation layer?

Can anyone point me in the direction of some decent articles or books explaining the architecture of such a set up and how a PHP app specifically would be designed in such a manner?

That’s correct, yes. When you build the application layer “app”, you would approach it as if you’re writing a REST API for all kinds of clients, such as mobile apps or third-party sites. Then your own site – your presentation “app” – would be just one more client that uses that REST API same as any other client.

Here’s a good case study: http://highscalability.com/blog/2013/7/8/the-architecture-twitter-uses-to-deal-with-150m-active-users.html

There is of course no single best method for doing this. However, consider using a modern Javascript application framework such as AngularJS to implement the view/controller/model stuff directly in your browser. PHP is reduced to providing the REST like web api. If nothing else, this will definitely show how the REST layer is independent of the rest of your application.