4. Introduction
• Ntvv2 (http://me.zing.vn/apps/ntvv2)
– 1.M daily active user
– Average 800 rps (per webserver) max 1100
rps
– 9300 rps (all database servers)
– 3 webservers
• Use Membase for cache and storage
• Use other db for secondary storage
• All bussiness function is moved to PHP
extension
5. Why to write PHP module?
Make complicated Bussiness functions run
faster, consume less memory
PHP high-level overhead cpu/mem
Advance facility with PHP-FPM
Cache something in PHP process
Strictly Confidential – Do Not Distribute
6. PHP extension basic
What is an extension?
Lifecycle
Setting up a build environment
http://devzone.zend.com/article/4486
http://devzone.zend.com/article/1021-Extension-Writing-Part-I-
Introduction-to-PHP-and-Zend
7. What is an extension?
Have you ever used PHP extension?
PHP consist of many extensions
All function we used is from extensions
11. SWIG
SWIG is an interface compiler that connects
programs written in C and C++ with
scripting languages such as PHP, Python,
Ruby...
How SWIG works
Using SWIG
Install module to PHP extensions
Sample
Strictly Confidential – Do Not Distribute
13. What does SWIG do for you ?
Namespace
Constants
Type conversion
For simple types (int, float, char *, enum)
Wraps complex types
Pointers to structs and classes
Exposes functions