Three tier PHP system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    Three tier PHP system

    Is there anyone who codes PHP in three tier?

    If you know anything about that, can you please send me links of some tutorials?

    I'm not able get good performance with the simple procedural coding style, so need to change the code to three tier (although its not going to be a week's job).


    Thanks
  • coolsti
    Contributor
    • Mar 2008
    • 310

    #2
    An interesting question, I look forward to reading the replies.

    But I am curious what you mean by not achieving good performance. Can you elaborate? Where do you think your bottlenecks are?

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      Originally posted by coolsti
      An interesting question, I look forward to reading the replies.

      But I am curious what you mean by not achieving good performance. Can you elaborate? Where do you think your bottlenecks are?
      Well, the major problem is scalability, which have been a big issue in my case since I started testing. And then the limited number of mysql connections. I get the error "Warning: Too many connections" quite frequently, when 50-100 users test it concurrently. And after some research, I have come to know that for the sites which could have many number of concurrent users, its recommended to adopt the three tier design.

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        Originally posted by hsriat
        Well, the major problem is scalability, which have been a big issue in my case since I started testing. And then the limited number of mysql connections. I get the error "Warning: Too many connections" quite frequently, when 50-100 users test it concurrently. And after some research, I have come to know that for the sites which could have many number of concurrent users, its recommended to adopt the three tier design.
        I must be quite ignorant, I thought 3 tier design was just html/php/mysql combination? But it sounds like you are using mysql, and you probably have html and php with that so, I'm a little lost. I know I'm not contributing to the solution, but I might be able to if I can research it myself.

        Regards

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          After some googling, I found this example. But still need some good tutorials.

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            Originally posted by hsriat
            After some googling, I found this example. But still need some good tutorials.
            I still think that's what I do in my php code. I have the normal page, with include()'s around the top in the most appropriate order (my order might be different tho). So I still don't understand how that will stream line your database calling. Have you optimized all your MySQL variable calling? Like only calling the specific variables needed for that page? You said that you had limited connections? If you have 100 users, all accessing the database, regardless of how you code, you will have 100 requests (and 100 connections - for each session)?

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Even I don't know how's that.
              That's why searching for some tutorials.

              Its good for you at least you could understand the code. I couldn't even do that. I've never used object oriented php. But I think I should learn it. Don't you think its better to use oop then procedural one?

              Comment

              • dlite922
                Recognized Expert Top Contributor
                • Dec 2007
                • 1586

                #8
                Originally posted by hsriat
                Is there anyone who codes PHP in three tier?

                If you know anything about that, can you please send me links of some tutorials?

                I'm not able get good performance with the simple procedural coding style, so need to change the code to three tier (although its not going to be a week's job).


                Thanks
                Three-tier, by which i assume you mean MVC ... Model View Controller.

                Large applications absolutly demand it. Luckily PHP 5 came through and all my applications are in MVC.

                I've created my own framework, which i find that i have more controll over vs. say zend.

                I highly suggest you design your own framework and experiment, then move on to a framework such as zend framework or things like this:
                Totoloka88 ✈️ Situs Toto Online Terakreditasi Dengan Bayaran Terbesar


                CakePHP is also another great one.

                For your database connection issue, what you can do is instead of connect() use pconnect()

                p = persistent.

                This way php/mysql do no create more connections, if the connection parameters are the same, it looks for a current one and uses it.

                An e-commerce site is the minimum you should use MVC for, otherwise, you'll have overhead. Its just unnecessary for small projects.

                Steps you should take:
                1. Read up on MVC (wikipedia) and IBM have great info
                2. Understand PHP classes and objects thoroughly (public, private, static, etc)
                3. Create your own MVC framework.

                To walk you through it, let's for example say i have a module in my app that manages customers and needs the CRUD functions. (Create, Read, Update, Delete)

                You create a DAO class. (Data Access Model) Call it CustomerDAO.php

                Then create a controller class, call it CustomerCT.php

                then create a customer Class, call it CustomerVO.php (Value Object)

                and finally you'll have a regular php file that will orchestrate and use the controller class.

                This php file will basically manage the actions. You read POST, see what action the user wants (add, delete, view, update) by reading POST vars.

                Then put those four funtions in a switch statement. Then call your (already instantiated at this point) conroller.

                $customerCT->getCustomer($_ GET['customer_id']);

                that should return a customerVO object, which then you can pass to your smarty like so

                $smarty->assign("custom erVO",$customer VO);

                and parse the customer info in Smarty!!!

                4. Pad yourself in the back for your first MVC class.

                If you need code to start from, I can email you some. (DAO is the toughest to get just right)

                Good luck,


                Dan

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  As I understand it, all PHP applications would be considered Tier-Three applications... At least if based on Wikipeida's definition of it.

                  The static content sent to the client's browser would be the 'Presentation Tier'.
                  The PHP code itself, doing all the back-end server stuff would be the 'Application Tier'
                  And the DBMS, whether it is MySQL or something else, would be the 'Data Tier'.

                  Am I wrong here?

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Originally posted by Atli
                    As I understand it, all PHP applications would be considered Tier-Three applications... At least if based on Wikipeida's definition of it.

                    The static content sent to the client's browser would be the 'Presentation Tier'.
                    The PHP code itself, doing all the back-end server stuff would be the 'Application Tier'
                    And the DBMS, whether it is MySQL or something else, would be the 'Data Tier'.

                    Am I wrong here?
                    Sounds right to me.

                    And OOP is a MUST.

                    I started learning it a week ago, just from online tutorials and I'm still finding it hard to grasp =/

                    MVC complicates me something rotten, so I shan't bother with it until I'm happy with my OOP.

                    *subscribing*

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      Originally posted by dlite922
                      Three-tier, by which i assume you mean MVC ... Model View Controller.
                      ............... ......

                      Good luck,

                      Dan
                      Hey! Thanks for that explanation.

                      I'll read all the stuff out on the website you told me. If I couldn't get it, then will ask for the code.

                      :)

                      Regards,
                      Harpreet

                      Comment

                      • hsriat
                        Recognized Expert Top Contributor
                        • Jan 2008
                        • 1653

                        #12
                        Originally posted by Atli
                        As I understand it, all PHP applications would be considered Tier-Three applications... At least if based on Wikipeida's definition of it.

                        The static content sent to the client's browser would be the 'Presentation Tier'.
                        The PHP code itself, doing all the back-end server stuff would be the 'Application Tier'
                        And the DBMS, whether it is MySQL or something else, would be the 'Data Tier'.

                        Am I wrong here?
                        No that's not the case. It's a bit different. I also used to think it this way, but not now.

                        Comment

                        • ronverdonk
                          Recognized Expert Specialist
                          • Jul 2006
                          • 4259

                          #13
                          Also have a peek at this thread Layers and Tiers

                          Ronald

                          Comment

                          • TheServant
                            Recognized Expert Top Contributor
                            • Feb 2008
                            • 1168

                            #14
                            I know it wasn't my question, but tanks for all the responses, you learn something new every day! Hmmm, *nervously looking at OOP* I guess if marcus said it's a must, I should give it a go :S

                            Comment

                            • dlite922
                              Recognized Expert Top Contributor
                              • Dec 2007
                              • 1586

                              #15
                              Originally posted by TheServant
                              I know it wasn't my question, but tanks for all the responses, you learn something new every day! Hmmm, *nervously looking at OOP* I guess if marcus said it's a must, I should give it a go :S
                              Learn Java. Find some tutorials and execute some classes using textpad, which has a compiler and a good editor to keep around to use instead of notepad.

                              Java is the like first grade for OOP.

                              Comment

                              Working...