SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Quake 1 Addict CreedFeed's Avatar
    Join Date
    Feb 2002
    Location
    Milwaukee, WI
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    http://i.imgur.com/sqI3rtf.jpg

    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?
    -- Steve Caponetto
    Quake 1 Resurrection :: CreedFeed

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,276
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CreedFeed View Post
    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.
    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...ive-users.html
    "First make it work. Then make it better."

  3. #3
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    689
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CreedFeed View Post
    From the programming standpoint, what's the best method of accomplishing such a set up.
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •