SlideShare a Scribd company logo
18/12/2010


Speed up ZingMe-NTVV2 with
PHP extension module




                     By Nguyen Trung Thanh
                        ZingMe Team leader
                       Web Technical - VNG
Contents

Introduction
Why?
PHP extension basic
SWIG
Sample
INTRODUCTION - ntvv2
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
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
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
What is an extension?

Have you ever used PHP extension?

PHP consist of many extensions

All function we used is from extensions
Lifecycle
Setting up build environment

- Setup PHP-devel
- Sample extension
Is it complicated?


●
 Is there any sexier and easier way?
●
 We can use SWIG
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
How SWIG works
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
Using SWIG

Defile module in swig file
Generate source code
Create module project, build it
Define module

Data type
Wrapper class/functions
                                            %module ntvv2module
                                            %{
                                            #include <string>
                                            #include <vector>
                                            #include <list>
                                            #include <string>
                                            #include “ntvvgame.h"
                                            %}
                                            struct LandInfo{
                                               int id;
                                               std::string data;
                                            }            ;
Strictly Confidential – Do Not Distribute   LandInfo updateLandInfo(int uid, int landID);
Exposure


•Swig recognizes C/C++ declarations
'struct' or 'class'
functions
•Hiding elements
%ignore solver::noupdate;
%include “satsolver/solver.h”
Useful commands
•Renaming
%rename("to_s") asString();
%rename( "name=" ) set_name( const char *name );
%rename("empty?") empty();
•Aliasing
%alias get "[]";
•Constants
%constant int Script = C_CONSTANT;
•Defines
%define YUILogComponent "bindings"
%enddef
%define %macro(PARAMETER)
SWIG steps

Generate code

Create project, compiling
    – Add genterated code to project
Running
    – Add extension module to PHP
Sample

Cache data in PHP module




Strictly Confidential – Do Not Distribute
Q&A

More Related Content

Viewers also liked (6)

PDF
Redoxsignalingmolecules
Nicolaas Eichelsheim
 
PDF
Giao trinh java script
Toàn Trần Mạnh
 
PDF
Mysql HandleSocket技术在SNS Feed存储中的应用
iammutex
 
PPTX
Mobilemonday.vn momo-monetize thinking_tu do tai chinh_v1.2
Quang Anh Le
 
PPTX
Mobilemonday.vn adflex
Quang Anh Le
 
PDF
Mobilemonday.vn mobile interaction - mr ng cuu long goldsun focus media
Quang Anh Le
 
Redoxsignalingmolecules
Nicolaas Eichelsheim
 
Giao trinh java script
Toàn Trần Mạnh
 
Mysql HandleSocket技术在SNS Feed存储中的应用
iammutex
 
Mobilemonday.vn momo-monetize thinking_tu do tai chinh_v1.2
Quang Anh Le
 
Mobilemonday.vn adflex
Quang Anh Le
 
Mobilemonday.vn mobile interaction - mr ng cuu long goldsun focus media
Quang Anh Le
 

Similar to 02. php ext module vng (20)

PDF
Usage Note of SWIG for PHP
William Lee
 
PDF
Perl-C/C++ Integration with Swig
David Beazley (Dabeaz LLC)
 
PDF
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
David Beazley (Dabeaz LLC)
 
PDF
Using SWIG to Control, Prototype, and Debug C Programs with Python
David Beazley (Dabeaz LLC)
 
PPTX
Php extensions
Elizabeth Smith
 
PPTX
Php extensions
Elizabeth Smith
 
PPT
Zpugdccherry 101105081729-phpapp01
Jeffrey Clark
 
PDF
Php on Windows
Elizabeth Smith
 
PPTX
Php extensions
Elizabeth Smith
 
PDF
Easy native wrappers with SWIG
Javier Arturo Rodríguez
 
PDF
Php Crash Course - Macq Electronique 2010
Michelangelo van Dam
 
ZIP
Inheritance Versus Roles
Curtis Poe
 
PPTX
Automation with phing
Joey Rivera
 
PDF
PHP, Cloud And Microsoft Symfony Live 2010
guest5a7126
 
PPTX
Kostiantyn Grygoriev "Wrapping C++ for Python"
LogeekNightUkraine
 
PDF
Tips And Tricks For Bioinformatics Software Engineering
jtdudley
 
PDF
Create your own PHP extension, step by step - phpDay 2012 Verona
Patrick Allaert
 
PDF
Software Development Automation With Scripting Languages
Ionela
 
PDF
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
David Beazley (Dabeaz LLC)
 
PPTX
Upstate CSCI 450 PHP Chapters 5, 12, 13
DanWooster1
 
Usage Note of SWIG for PHP
William Lee
 
Perl-C/C++ Integration with Swig
David Beazley (Dabeaz LLC)
 
SWIG : An Easy to Use Tool for Integrating Scripting Languages with C and C++
David Beazley (Dabeaz LLC)
 
Using SWIG to Control, Prototype, and Debug C Programs with Python
David Beazley (Dabeaz LLC)
 
Php extensions
Elizabeth Smith
 
Php extensions
Elizabeth Smith
 
Zpugdccherry 101105081729-phpapp01
Jeffrey Clark
 
Php on Windows
Elizabeth Smith
 
Php extensions
Elizabeth Smith
 
Easy native wrappers with SWIG
Javier Arturo Rodríguez
 
Php Crash Course - Macq Electronique 2010
Michelangelo van Dam
 
Inheritance Versus Roles
Curtis Poe
 
Automation with phing
Joey Rivera
 
PHP, Cloud And Microsoft Symfony Live 2010
guest5a7126
 
Kostiantyn Grygoriev "Wrapping C++ for Python"
LogeekNightUkraine
 
Tips And Tricks For Bioinformatics Software Engineering
jtdudley
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Patrick Allaert
 
Software Development Automation With Scripting Languages
Ionela
 
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
David Beazley (Dabeaz LLC)
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
DanWooster1
 
Ad

More from Quang Anh Le (20)

PDF
02 mobile monday hanoi april 2013 vinova
Quang Anh Le
 
PPT
01 mobile monday hanoi april 2013 mobile game - afoli
Quang Anh Le
 
PPTX
03 mobile monday hanoi april 2013 monetize thinking g mo m-work
Quang Anh Le
 
PPT
2. minh chau momo t4
Quang Anh Le
 
PPT
0. mobilemonday.vn hcm 20130424
Quang Anh Le
 
PPT
Vietnam mobile day 2012 phan mem cho phai dep - mana
Quang Anh Le
 
PPTX
Vietnam mobile day 2012 i os memory management - techmaster
Quang Anh Le
 
PPTX
Vietnam mobile day 2012 monetizing mobile apps games - rubycell
Quang Anh Le
 
PDF
Vietnam mobile day 2012 cuoc cach mang thoi ky hau mobile - misfit
Quang Anh Le
 
PPTX
Vietnam mobile day 2012 multi platform development - game loft
Quang Anh Le
 
PDF
Vietnam mobile day 2012 developer opportunity - nokia
Quang Anh Le
 
PPT
Vietnam mobile day 2012 building a mobile linux firmware for your router - ...
Quang Anh Le
 
PPT
Vietnam mobile day 2012 ban quyen mobile contents - vsm
Quang Anh Le
 
PDF
Vietnam mobile day 2012 platform mo va ung dung de phat trien mang xa hoi m...
Quang Anh Le
 
PPT
Vietnam mobile day 2012 co hoi mobile tai vietnam - cyber agent
Quang Anh Le
 
PPTX
Vietnam mobile day 2012 html5 game using impact js - aiti-aptech
Quang Anh Le
 
PPTX
Vietnam mobile day 2012 tuong lai cho nha phat trien nds - share plus
Quang Anh Le
 
PPSX
Vietnam mobile day 2012 trends in mobile marketing - fifth i media
Quang Anh Le
 
PPTX
Vietnam mobile day 2012 thi hieu nguoi dung mobile - app storevn
Quang Anh Le
 
PPTX
Vietnam mobile day 2012 new platform - new opportunity - appota
Quang Anh Le
 
02 mobile monday hanoi april 2013 vinova
Quang Anh Le
 
01 mobile monday hanoi april 2013 mobile game - afoli
Quang Anh Le
 
03 mobile monday hanoi april 2013 monetize thinking g mo m-work
Quang Anh Le
 
2. minh chau momo t4
Quang Anh Le
 
0. mobilemonday.vn hcm 20130424
Quang Anh Le
 
Vietnam mobile day 2012 phan mem cho phai dep - mana
Quang Anh Le
 
Vietnam mobile day 2012 i os memory management - techmaster
Quang Anh Le
 
Vietnam mobile day 2012 monetizing mobile apps games - rubycell
Quang Anh Le
 
Vietnam mobile day 2012 cuoc cach mang thoi ky hau mobile - misfit
Quang Anh Le
 
Vietnam mobile day 2012 multi platform development - game loft
Quang Anh Le
 
Vietnam mobile day 2012 developer opportunity - nokia
Quang Anh Le
 
Vietnam mobile day 2012 building a mobile linux firmware for your router - ...
Quang Anh Le
 
Vietnam mobile day 2012 ban quyen mobile contents - vsm
Quang Anh Le
 
Vietnam mobile day 2012 platform mo va ung dung de phat trien mang xa hoi m...
Quang Anh Le
 
Vietnam mobile day 2012 co hoi mobile tai vietnam - cyber agent
Quang Anh Le
 
Vietnam mobile day 2012 html5 game using impact js - aiti-aptech
Quang Anh Le
 
Vietnam mobile day 2012 tuong lai cho nha phat trien nds - share plus
Quang Anh Le
 
Vietnam mobile day 2012 trends in mobile marketing - fifth i media
Quang Anh Le
 
Vietnam mobile day 2012 thi hieu nguoi dung mobile - app storevn
Quang Anh Le
 
Vietnam mobile day 2012 new platform - new opportunity - appota
Quang Anh Le
 
Ad

Recently uploaded (20)

PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 

02. php ext module vng

  • 1. 18/12/2010 Speed up ZingMe-NTVV2 with PHP extension module By Nguyen Trung Thanh ZingMe Team leader Web Technical - VNG
  • 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
  • 9. Setting up build environment - Setup PHP-devel - Sample extension
  • 10. Is it complicated? ● Is there any sexier and easier way? ● We can use SWIG
  • 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
  • 14. Using SWIG Defile module in swig file Generate source code Create module project, build it
  • 15. Define module Data type Wrapper class/functions %module ntvv2module %{ #include <string> #include <vector> #include <list> #include <string> #include “ntvvgame.h" %} struct LandInfo{ int id; std::string data; } ; Strictly Confidential – Do Not Distribute LandInfo updateLandInfo(int uid, int landID);
  • 16. Exposure •Swig recognizes C/C++ declarations 'struct' or 'class' functions •Hiding elements %ignore solver::noupdate; %include “satsolver/solver.h”
  • 17. Useful commands •Renaming %rename("to_s") asString(); %rename( "name=" ) set_name( const char *name ); %rename("empty?") empty(); •Aliasing %alias get "[]"; •Constants %constant int Script = C_CONSTANT; •Defines %define YUILogComponent "bindings" %enddef %define %macro(PARAMETER)
  • 18. SWIG steps Generate code Create project, compiling – Add genterated code to project Running – Add extension module to PHP
  • 19. Sample Cache data in PHP module Strictly Confidential – Do Not Distribute
  • 20. Q&A