SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Expert advice needed on building a scalable, high performance site with php

    Hi,

    i need to code a very scalable, high performance application.



    It's a quiz application that should allow millions of users at the same time to answer questions, so the performance should not go down with increase in number of users and the application should be able to scale.



    Currently i know some but not all oop concepts from java and have done some procedural php programming in the past. If i was to code this application in php, i need to know:


    How much time would it take me to learn oop for php and maybe a mvc architecture(if that's what we need to write scalable, high performance applications)?

    I have a little over 2 months time to learn and do this peoject.

    Any books/tutorials that are easy and quick to learn oo php and mvc? Nice if these tutorials move from covering essential theory in detail to practical code examples quickly. I'm not looking at books wuth hundreds of pages of theory that might just bog me down.


    How would you design a database that performs well for such a system.

    Would it be better having a denormalized data structure instead of a one that is normalised too far? Maybe so that there are lesser no. of joins etc. so that query retrieval is faster?

    Any pointers to tutorials/books on this would be nice too.




    Any help is much appreciated. Many thanks.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't think you have enough time for this project if you actually expect millions of people to be using the site at the same time.

    Not only do you need to learn how to program it, you then need to learn server administration, the API of a cloud hosting service like Amazon S3, load balancing, database partitioning, caching, lots of advanced topics to support that kind of load.

    You could use the 2 months just taking an existing working application and preparing it to scale to that kind of usage level... so doing that AND learning OOP AND programming the application, no way.

  3. #3
    SitePoint Addict webaddictz's Avatar
    Join Date
    Feb 2006
    Location
    Netherlands
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spuser2006 View Post
    I have a little over 2 months time to learn and do this peoject.
    As always; stick to what you know, especially on strict deadlines. Not saying you shouldn't learn (quite the opposite), but never try to implement newly learned techniques on a tight schedule: you simply won't make it as you'll always run into things you didn't count on. Use "pet projects" (if you have any) to try to implement newly learned things, or just stuff you do in your own time.

    If you program your application procedurally while keeping different responsibilities apart (eg. best practises), you'll have the opportunity to refactor the procedural application to an object oriented one when you have the time and experience to do so. You'll have to do a few things right when writing the procedural application though:

    • Use templates for everything you display
    • Keep all database related code apart from the template handling.
    • Use one page (and one file) for one display.


    I tend to write procedural applications on occasion, mostly for prototyping (it's just quicker). A "page" (display of a resource) usually looks like this (a page which displays a user):

    PHP Code:
    require_once( '../bootstrap.php' );
    require_once( 
    'user.database.php' );
    require_once( 
    '../lib/http.php' );
    if( 
    isPost( ) ) {
         
    $user = array(
             
    'username' => $_POST['username']
             
    // etc.
         
    );
         if( 
    isValid$_POST ) ) {

               if( 
    saveUser$user ) ) {
                     
    flash'User has been saved.' );
                     
    redirect'users.php' );
               }
               else {
                      
    $errors getDatabaseErrors( );
               }
          }
          else {
              
    $validationerrors getValidationErrors( );
    }
    render'templates/adduser.tpl.php', array( 'variable' => 'value' ); 
    Doing it this way will help you tremendously when converting the system to OO, if you ever feel the need to.

    I do agree with Dan though: two months to write an application that performs like crazy is undoable, unless you have a lot of programmers working on it.
    Yes, I blog, too.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx Dan and Webaddictz,


    I am only interested in coding the application with best practises and building an architecture that is scalable and perfromance oriented.

    Once i do that, i'll handover the application, so i will not be doing anything regarding server, load balancing, database partitioning, cloud hosting etc. etc.


    My only aim in respect to writing this application is that i deliver an application that can scale and perform if required in the future. If the application grows as it's intended owners think it would, it should be able to handle that kind of load.


    Do you think learning and implementing best practises like oop approach and mvc cannot be done in about 75 days time considering that the application's only real functionality that needs to be implemented with this approach is generating random questions, with the only catch being that if the site grows to milliions of users it should be able to handle the load?


    Additionally, I have seen some of the sections in the Advanced Resources Post which are nice but i'm looking at something which is more upto date and latest ( since version 5, lots of new oop features added to php) regarding the php language and i can read at one place instead of reading different posts(though i have been looking at that too....)

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And yes Webaddictz, you can consider this a my pet project with the only exception being that i have about 75 days to do this. I am doing this for someone i know and as such i am allowed to experiment.

  6. #6
    SitePoint Addict webaddictz's Avatar
    Join Date
    Feb 2006
    Location
    Netherlands
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spuser2006 View Post
    Do you think learning and implementing best practises like oop approach and mvc cannot be done in about 75 days time considering that the application's only real functionality that needs to be implemented with this approach is generating random questions, with the only catch being that if the site grows to milliions of users it should be able to handle the load?
    No, you can't and shouldn't. Besides: OOP and MVC are *not* going to make your application perform better, the opposite is true, it'll make your application slower. OOP is slower than procedural, but it has the benifit that it's a heck of a lot easier to maintain and extend. If you want sheer performance, don't use PHP, use C.
    Yes, I blog, too.

  7. #7
    SitePoint Zealot GOPalmer's Avatar
    Join Date
    Jan 2009
    Location
    Wiltshire, UK
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its much more important to have a solid design in mind and on paper. The choice of php4 or 5 is neither here nor there. At the end of the day a sloppy application will never perform as well as a well planed piece. Rather that spending your time learning php5 and oop you should consider spending more time planning the application.

  8. #8
    SitePoint Addict webaddictz's Avatar
    Join Date
    Feb 2006
    Location
    Netherlands
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by GOPalmer View Post
    Its much more important to have a solid design in mind and on paper. The choice of php4 or 5 is neither here nor there.
    No, the choice for PHP 4 or 5 is already made: php 5 is mainstream, performs better, well tested and.. uhm.. not dead like php 4. If anyone still uses php 4, you might wish to consider upgrading, as it's officially no longer supported.
    Yes, I blog, too.

  9. #9
    SitePoint Zealot GOPalmer's Avatar
    Join Date
    Jan 2009
    Location
    Wiltshire, UK
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webaddictz View Post
    No, the choice for PHP 4 or 5 is already made: php 5 is mainstream, performs better, well tested and.. uhm.. not dead like php 4. If anyone still uses php 4, you might wish to consider upgrading, as it's officially no longer supported.
    Maybe i would have been better of saying procedural or oop (not that php4 necessarily means procedural). My bad.

    On a side note. There is still a very large number of websites running on php4.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webaddictz View Post
    No, you can't and shouldn't. Besides: OOP and MVC are *not* going to make your application perform better, the opposite is true, it'll make your application slower. OOP is slower than procedural, but it has the benifit that it's a heck of a lot easier to maintain and extend. If you want sheer performance, don't use PHP, use C.


    That makes me pretty sad.......


    Forget the time frame, can you people please point me in the right direction to learn all the latest best practises with example code...... Some easy to understand, practical tutorials.....

  11. #11
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you want to stick to the 2 month limit, there's no hope in hell you're going to finish that if you're still at the point at which you require tutorials.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  12. #12
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can do it, follow your dreams

  13. #13
    SitePoint Guru
    Join Date
    Jun 2006
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try: Quercus & PHP
    It's faster than plain PHP, and since you use JAVA for most of the business logic, it's ~8x faster than PHP for the OOP and you can extend it easier.

    But if you need "code examples", your looking at a good 5 year learning curve till you can get a site up in 2 months that can handle "millions of users"

  14. #14
    SitePoint Addict chestertondevelopment's Avatar
    Join Date
    Dec 2005
    Location
    Essex, UK
    Posts
    241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly OOP is slightly slower than procedural PHP yes, but the difference is negligible. Code it right and worry about performance later. As an example, using memcached in the right places will make your site 1000x faster than sticking to procedural PHP will, with no major drawbacks. OOP is, if done right, more maintainable and extendable.

    Have a look at the slides from a recent PHP|tek conference for some guidelines on good OOP code - http://www.priebsch.de/2009/05/seven...tter-oop-code/

    Also, do you know you will be having millions of users? Build it, get it popular and then worry about scaling. Scaling is a lot easier these days with things like Amazon S3, EC2. That's not to say don't build your application right in the first place but don't put too much emphasis on scaling until you have to.

  15. #15
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spuser2006 View Post
    Once i do that, i'll handover the application, so i will not be doing anything regarding server, load balancing, database partitioning, cloud hosting etc. etc.
    If your application is not built with awareness of these things when you hand it over, it won't be easy to add these things. These are the all the things that will enable your system to handle massive load, not OOP.

    In your time frame, I'd go with an amazon EC2/Web services stack. Use
    EC2 and use their load balancing service and autoscaling service. Use SimpleDB.

    Its not an impossible task.

  16. #16
    SitePoint Addict webaddictz's Avatar
    Join Date
    Feb 2006
    Location
    Netherlands
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webaddictz View Post
    No, you can't and shouldn't. Besides: OOP and MVC are *not* going to make your application perform better, the opposite is true, it'll make your application slower. OOP is slower than procedural, but it has the benifit that it's a heck of a lot easier to maintain and extend. If you want sheer performance, don't use PHP, use C.
    Uhm.. rereading my own post, I think it's important to clarify a little: OO is slower as it has the overhead of constructing and destructing objects, but written with best practices such as autoloading classfiles, it might not make that much of a difference.
    Yes, I blog, too.

  17. #17
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    A single simple database query will take longer than the entire overhead of running an OOP program versus its procedural equivalent. It really doesn't matter even to extremely high traffic sites.


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
  •