7. Code Tweaks – String replacement
(preg_replace vs str_replace)
• Data sets Templa&ng
Fo&s Alexandrou ‐ @falexandrou ‐
www.redmark.gr
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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