SlideShare a Scribd company logo
1 of 14
Download to read offline
PHP Op&miza&on & Scalability 
       Techniques 
                        Fo&s Alexandrou 
                         Web Developer 
         (e‐skafos.gr, iheartshops.com & many more) 

  Disclaimer: Highly Technical Presenta&on, might cause brain 
                            injuries 



                    Fo&s Alexandrou ‐ @falexandrou ‐ 
                            www.redmark.gr 
When is op&miza&on needed 
•  Web Applica&ons 
•  Websites with lots of traffic 
  – E‐Skafos case study 
•  Websites that are promising high traffic 
  – iHeartShops case study 




                   Fo&s Alexandrou ‐ @falexandrou ‐ 
                           www.redmark.gr 
Easy Stuff 
•  Opcode Caching – Boot and forget – Pre‐
   compiled code loaded in memory (runs a lot 
   faster) 
  – APC  
  – Xcache 
•  Pecl Extensions 
•  Minimum Configura&on 


                 Fo&s Alexandrou ‐ @falexandrou ‐ 
                         www.redmark.gr 
Advanced Stuff ‐ Memcache 
•  Storage engine using keys 
•  Re‐seXng aYer data update 
•  Memcache became really popular aYer 
   Facebook started using it 
•  Cheat: Write a class that extends it ;) 




                  Fo&s Alexandrou ‐ @falexandrou ‐ 
                          www.redmark.gr 
Advanced Stuff – Code Tweaks 
•  “echo“ func&on faster than print 
•  Single quotes (‘) faster than double quotes (“) 
•  Using short tags “<?” is more expensive than 
   “<?php” 
•  The shut up equator (@)  
•  Leave Magic to David Coperfield (__get(), 
   __set(), __autoload()) 

                   Fo&s Alexandrou ‐ @falexandrou ‐ 
                           www.redmark.gr 
Code Tweaks – String replacement 
•  str_replace faster than preg_replace (not 
   always) 
  – str_replace faster for templa&ng 
  – preg_replace faster for large data sets 
•  str_replace($array1, $array2, $subject) a lot 
   faster than loops 



                    Fo&s Alexandrou ‐ @falexandrou ‐ 
                            www.redmark.gr 
Code Tweaks – String replacement 
    (preg_replace vs str_replace) 
•  Data sets              Templa&ng 




               Fo&s Alexandrou ‐ @falexandrou ‐ 
                       www.redmark.gr 
Code Tweaking ‐ Loops 
•  NEVER use func&ons inside a for – they’re 
   called upon each loop! 
•  Bad: 
  for ($i = 0; $i<count($array); $i++){ 
  ……. 
  } 

•  Good: 
  $count = count($array) //Called once 
  for ($i = 0; $i<$count; $i++){ 
  ……. 
  } 
                            Fo&s Alexandrou ‐ @falexandrou ‐ 
                                    www.redmark.gr 
Code Tweaks – Constants &  Sta&c 
•  Constants are your friends 
  $foo = array(‘bar’=>0); 
  $foo[‘bar’] = 1; 
  Is 700% slower than 
  $foo[‘bar’] = 1; 
•  Sta&cs are also your friends 
  – Declaring sta&c func&ons is 4 &mes faster! 


                    Fo&s Alexandrou ‐ @falexandrou ‐ 
                            www.redmark.gr 
Code Tweaks – Proper coding 
•  Go with the flow: 
  – Ini&alize your variables 
  – Use singleton classes 
  – Study SQL & avoid PHP juggling when SQL can do 
    the hard work 




                  Fo&s Alexandrou ‐ @falexandrou ‐ 
                          www.redmark.gr 
Use a second web server for sta&c 
                 stuff 
•  Install a second web server on second IP (eg. 
   Ligh{pd) and replace images, css, js, mov, flv 
   paths 
•  Avoid main webserver overhead 
•  Tune up your main web server 
•  Use mod_compress on ligh{pd 



                  Fo&s Alexandrou ‐ @falexandrou ‐ 
                          www.redmark.gr 
SQL op&miza&on 
•  Replica&on 
  – Use master server for inserts, updates, deletes 
  – Use slave server for selects 
•  Use memcache for database stuff (selects or 
   stored procedures) 
•  Mul&ple Databases 



                   Fo&s Alexandrou ‐ @falexandrou ‐ 
                           www.redmark.gr 
Deploy to the Cloud 
•  Windows Azure 
  – Available on Monday 12/4/10 (for Greece) 
  – Programmer != Sysadmin 
  – Add instances easily 
•  Amazon EC2 
  – You need an experienced administrator 
•  Other par&es 
•  Cheaters (Selling dedicated servers as cloud) 
                  Fo&s Alexandrou ‐ @falexandrou ‐ 
                          www.redmark.gr 
Thank you! 
•  Ques&ons 
•  Contact Informa&on 
  – fo&s@redmark.gr 
  – twi{er.com/falexandrou 
  – facebook.com/falexandrou 

  – www.redmark.gr ‐ www.e‐skafos.gr ‐ 
     www.iheartshops.com 
  ‐ Thnx to @HumanWorks for the &ps   
                  Fo&s Alexandrou ‐ @falexandrou ‐ 
                          www.redmark.gr 

More Related Content

What's hot

Optimizing WordPress - WordPress SF Meetup April 2012
Optimizing WordPress -  WordPress SF Meetup April 2012Optimizing WordPress -  WordPress SF Meetup April 2012
Optimizing WordPress - WordPress SF Meetup April 2012
Ben Metcalfe
 

What's hot (10)

Using Wordpress for Internet Publishing
Using Wordpress for Internet PublishingUsing Wordpress for Internet Publishing
Using Wordpress for Internet Publishing
 
Optimizing WordPress - WordPress SF Meetup April 2012
Optimizing WordPress -  WordPress SF Meetup April 2012Optimizing WordPress -  WordPress SF Meetup April 2012
Optimizing WordPress - WordPress SF Meetup April 2012
 
RPC-CMS-Blog-Platforms
RPC-CMS-Blog-PlatformsRPC-CMS-Blog-Platforms
RPC-CMS-Blog-Platforms
 
WP-CLI Presentation from WordCamp NYC 2015
WP-CLI Presentation from WordCamp NYC 2015WP-CLI Presentation from WordCamp NYC 2015
WP-CLI Presentation from WordCamp NYC 2015
 
Creating Multilingual WordPress Websites
Creating Multilingual WordPress WebsitesCreating Multilingual WordPress Websites
Creating Multilingual WordPress Websites
 
Manage WordPress From the Command Line with WP-CLI
Manage WordPress From the Command Line with WP-CLIManage WordPress From the Command Line with WP-CLI
Manage WordPress From the Command Line with WP-CLI
 
PHPDay 2013 - High Performance PHP
PHPDay 2013 - High Performance PHPPHPDay 2013 - High Performance PHP
PHPDay 2013 - High Performance PHP
 
WordPress Migrations 101 - WordCamp Orlando
WordPress Migrations 101 - WordCamp OrlandoWordPress Migrations 101 - WordCamp Orlando
WordPress Migrations 101 - WordCamp Orlando
 
Booking.Com And Perl - Success story
Booking.Com And Perl - Success storyBooking.Com And Perl - Success story
Booking.Com And Perl - Success story
 
Key learnings from hosting 1000+ WordPress sites
Key learnings from hosting 1000+ WordPress sitesKey learnings from hosting 1000+ WordPress sites
Key learnings from hosting 1000+ WordPress sites
 

Viewers also liked (6)

Effectiveness of freshman seminars
Effectiveness of freshman seminars Effectiveness of freshman seminars
Effectiveness of freshman seminars
 
Hacking the way you work
Hacking the way you workHacking the way you work
Hacking the way you work
 
Fall Academic Calendar - Council Study & Proposal
Fall Academic Calendar - Council Study & ProposalFall Academic Calendar - Council Study & Proposal
Fall Academic Calendar - Council Study & Proposal
 
Proposal for student training
Proposal for student trainingProposal for student training
Proposal for student training
 
Technology adoption proposal presentation student name
Technology adoption proposal presentation student nameTechnology adoption proposal presentation student name
Technology adoption proposal presentation student name
 
Sustainable in asset management
Sustainable in asset managementSustainable in asset management
Sustainable in asset management
 

Similar to Fotis alexandrou scalability on php - media camp 2010

Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
Fix me if you can - DrupalCon prague
Fix me if you can - DrupalCon pragueFix me if you can - DrupalCon prague
Fix me if you can - DrupalCon prague
hernanibf
 

Similar to Fotis alexandrou scalability on php - media camp 2010 (20)

Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopment
 
Big Data Introduction - Solix empower
Big Data Introduction - Solix empowerBig Data Introduction - Solix empower
Big Data Introduction - Solix empower
 
PySpark Best Practices
PySpark Best PracticesPySpark Best Practices
PySpark Best Practices
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
SAS and Cloudera – Analytics at Scale
SAS and Cloudera – Analytics at ScaleSAS and Cloudera – Analytics at Scale
SAS and Cloudera – Analytics at Scale
 
Amp and higher computing science
Amp and higher computing scienceAmp and higher computing science
Amp and higher computing science
 
Monitoring the unknown, 1000*100 series a day - Big Data Vilnius 2017
Monitoring the unknown, 1000*100 series a day - Big Data Vilnius 2017Monitoring the unknown, 1000*100 series a day - Big Data Vilnius 2017
Monitoring the unknown, 1000*100 series a day - Big Data Vilnius 2017
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slides
 
Big Data answers in seconds with Amazon Athena
Big Data answers in seconds with Amazon AthenaBig Data answers in seconds with Amazon Athena
Big Data answers in seconds with Amazon Athena
 
Netconf for Peering Automation by Tom Paseka [APRICOT 2015]
Netconf for Peering Automation by Tom Paseka [APRICOT 2015]Netconf for Peering Automation by Tom Paseka [APRICOT 2015]
Netconf for Peering Automation by Tom Paseka [APRICOT 2015]
 
APRICOT 2015 - NetConf for Peering Automation
APRICOT 2015 - NetConf for Peering AutomationAPRICOT 2015 - NetConf for Peering Automation
APRICOT 2015 - NetConf for Peering Automation
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 
Fix me if you can - DrupalCon prague
Fix me if you can - DrupalCon pragueFix me if you can - DrupalCon prague
Fix me if you can - DrupalCon prague
 
Introduction to rest using flask
Introduction to rest using flaskIntroduction to rest using flask
Introduction to rest using flask
 
Aws, an intro to startups
Aws, an intro to startupsAws, an intro to startups
Aws, an intro to startups
 
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
 
Terraform: Infrastructure as Code
Terraform: Infrastructure as CodeTerraform: Infrastructure as Code
Terraform: Infrastructure as Code
 
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 PotsdamFrom Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
 
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
 

Fotis alexandrou scalability on php - media camp 2010