This document discusses speeding up the ZingMe-NTVV2 application by writing a PHP extension module. It introduces NTVV2, which has high traffic volumes. Writing a PHP extension can make complicated business functions run faster and use less memory compared to pure PHP. The document explains what a PHP extension is, its lifecycle, and how to set up the build environment. It recommends using SWIG, an interface compiler, to more easily connect C/C++ programs to PHP. SWIG allows defining types, wrapping classes/functions, and exposing functions to PHP. The document provides steps for using SWIG, including defining the module, generating code, creating a project, and compiling. Caching data in the PHP module
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