Académique Documents
Professionnel Documents
Culture Documents
Servers
Load Balancer (assigns a web server)
Hello World!
Problems we encounter using PHP at scale
1) High CPU usage
Problem 1: High CPU
▪ Tens of thousands of web servers
CPU by Language
▪ Up to 800ms for each request
40
▪ Slower as the codebase 32
Unit of Time
continues to grow 24
16
▪ Hardware isn’t free 8
0
C++ Java C# Erlang Python Perl PHP
CPU Usage
http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang=all
2) High memory usage
Problem 2: High Memory
150MB
700MB
for ($i = 0; $i < 5000000; $i++) {
$a[] = $i;
}
Infrastructure Modules
4) Extensions are hard to write for
most PHP developers
PHP is problematic for Facebook
0% 90%
six months
How HipHop works
HipHop Source Code
1 Code transformation
2 Runtime
1) Code Transformation
$x = 1;
$$x = $$y;
eval($x . $y);
Magic
$$$$$foo();
Type
Static Pre- Post-
Parser Analyzer Optimizer
Inference
Optimizer
Code g++
Engine Generator
2) Runtime
Runtime vs Generation
Programming with HipHop
Supported magical PHP features
▪ dynamic function call, including call_user_func()
▪ dynamic object properties and methods
▪ dynamic variables, including extract()
▪ dynamic includes
▪ re-declared functions
▪ re-declared classes
▪ re-declared constants
▪ magic methods: __toString(), __get(), __set(), __call()
Features not supported
1.Dynamic coding
• eval()
• create_function()
• preg_replace when using /e
2.Order-dependent symbol lookups: function, class, constant
if (function_exists(‘foo’)) {
print ‘foo missing’; // side-effect
}
function foo() {
}
HPHPi – The experimental interpreter
▪ Make it easy for developers and don’t change their process
▪ HPHPi is an experimental interpreter
▪ Wanted an interpreter to help catch bugs in our implementation
▪ More runtime checks
▪ eval() support
▪ It sounded fun
▪ Innovation: You don’t have to compile your PHP to run it! <applause>
Deploying HipHop in production
▪ Pre-compiled binary versus PHP source code
▪ HipHop is different...
▪ Runs as one process with multiple threads
▪ No downtime during restarts (port takeover)
▪ Pushing a large binary
▪ We spread our compile across multiple machines