Everyone loves PHP

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    5 Favorites

    Everyone loves PHP - Presentation Transcript

    1. PHP Everyone loves PHP
    2. Agenda
      • PHP Basics
      • Why PHP is so popular in Web 2.0 world
      • Comparison of various platforms (php, ruby, java)
      • Scaling out Database tier
      • Scaling out Web tier
      • Caching (APC/Memcached)
    3. PHP Basics
    4. What is PHP?
      • Server side Scripting language
        • Virtual Machine : Zend Engine
        • Written in C
        • Object Oriented (from PHP 5.0)
        • Weak typing
    5. Cool Stuff – PHP Array
    6. PHP Array
      • an ordered map - A map is a type that associates  values  to  keys
    7. <?php $arr  = array( &quot;foo&quot;  =>  &quot;bar&quot; ,  12  =>  true ); echo  $arr [ &quot;foo&quot; ];  // bar echo  $arr [ 12 ];     // 1 ?>
    8. <?php $arr  = array( &quot;foo&quot;  =>  array(1, 2) ,  12  =>  array( “ user1 ”=>array( “ name” => ‘mark’, “ gender” => ‘male’ ) ) ); ?>
    9. Juggling with variables
    10. Why PHP is so popular in Web 2.0 world 99880… Larry@… Larry 98778… Mark@… Mark phone email name
    11. Execute Query Select * from <table> where email = ‘Mark@…’
    12. What is returned from DB is a PHP Array object $arr  = array( “ name&quot;  =>”Mark”, “ email&quot;  =>”Mark@…”, “ phone&quot;  =>”98778…”, )
    13. The same object can be pushed to JAVA-Script layer for Processing var jsvar  = array( “ name&quot;  =>”Mark”, “ email&quot;  =>”Mark@…”, “ phone&quot;  =>”98778…”, )
    14. So what we gained …
      • No need to have an intermediate object like java beans to store the DB result
      • PHP array can be sent directly to javascript layer for processing
        • Java script array notation is same as php array notation …
      • No need to write unnecessary code to handle the DB  Front end communication
    15.  
    16. Scaling
    17. Terminology: Scaling
      • NOT how fast your code is
      • How fast your code will be tomorrow
      • Can it scale out?
        • Run in parallel?
    18. Scale out or Scale up ?
    19. Cloud Computing Amazon Cloud
    20. Amazon Cloud Components
      • Amazon Elastic Cloud Computing (EC2)
      • Amazon Simple Storage Service (S3)
      • Amazon Simple Queuing service (SQS)
      • Utilities
        • Distributed computing framework (HADOOP)
        • Amazon Payment service
    21. Growing Up, “One Box” solution
      • Basic web application (discussion board, etc.)
      • Low traffic
      • Apache/PHP/MySQL on one machine
      • Bottlenecks will start showing up:
        • Most likely database before apache/php
        • Disk I/O (Innodb) or locking wait states (MyISAM)
    22. InnoDB vs. MyISAM
    23. 90% Read 60% Read 99880… Larry@… Larry 98778… Mark@… Mark phone email name I like it … Photo #4 Larry@… This is great Photo #1 Mark@… comment resource email
    24.  
    25. Growing Up, “Two Box” solution
      • Higher traffic application
      • Apache/PHP on Box A, MySQL on Box B
      • Bottlenecks will be
        • Disk I/O on MySQL Box
        • Locking on MyISAM tables
        • Network I/O
    26.  
    27. Growing Up, “Many Boxes with Replication” solution
      • Yet even higher traffic
      • Writes are separated from reads (master gets IN/UP/DEL, slaves get SELECTs)
      • SELECTs, IN/UP/DEL can be specified within the application,
      • Or
      • Load-balancing can be used
    28.  
    29. Bottlenecks …
      • As you have multiple slaves
        • Your code will decide “Execute Select command in Slave #4”
        • But how will you decide it ?
    30. Using Hardware Load Balancer
    31. How its usually done?
      • Standard MySQL Master/Slave replication
      • All writes (Insert/Delete/Update) from application go to master
      • All reads (Selects) from application go to a load balancer which will spread out load across all slaves.
    32.  
    33. What is good about load balancing ?
      • You can add/remove slaves without affecting the application.
      • Additional monitoring point and automatic failure detection
      • You can treat all your slave pool as one resource.
    34. Only one Master Database … the Next Bottleneck …
    35. Use NDB Cluster
    36.  
    37. Scaling out Web tier
    38. Design Change
      • Store your Session variable in Database
      • Always access Session from DB
      • Remove the Session entry from DB on Logout
      • Update the session entry periodically to handle session hijacking attack …
    39. #1 #2 #3 #4 Load Balancer DB Layer
    40. Caching (APC/Memcached)
    41.  
    42.  
    43. Where should we store the value
      • Local database is faster than shared database
      • Local Disk faster than database
      • RAM is faster than disk
    44. What we will store
      • Anything you don’t want to fetch or compute every time your code runs
      • Anything that’s not going to change very often
    45. Everybody is doing it
      • WP_Cache (Wordpress)
      • Memcache
        • Live journal
        • Slashdot
        • wikipedia
    46. Even PHP Itself Is Getting Cached
      • PHP opcode caches compile your scripts and run these pre-parsed versions instead.
        • Zend Optimizer
        • APC (Alternative PHP Cache)
        • Xcache
        • eAccelerator
        • ionCube
    47.  
    48. Of course OS caches files
      • Modern operating systems use all your free RAM as a disk cache.
      • If you read the same file over & over, it's probably being read out of RAM the second time on. So, it's usually ok to read a small file over & over.
    49. Memcached memcached is a high-performance, distributed memory object caching system
    50.  
    51.  
    52. Thank You
    53.  

    + meetupdiarymeetupdiary, 4 months ago

    custom

    307 views, 5 favs, 1 embeds more stats

    PHP / Mysql / Scaling

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 307
      • 302 on SlideShare
      • 5 from embeds
    • Comments 0
    • Favorites 5
    • Downloads 0
    Most viewed embeds
    • 5 views on http://192.168.10.3

    more

    All embeds
    • 5 views on http://192.168.10.3

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories