Building PHP extensions with C++, the easy way (update: MySQL, threads)
Here is an easy way to build a PHP extension with C++ and default PHP packages on a Ubuntu system. I use SWIG to wrap C++ code to the Zend API. When using loops and recursion intensively, porting a few functions to C++ can give you some extra power . First, install all required packages (tested with Ubuntu 12.10) : apt-get install php5-cli php5-dev swig g++ Second, write the code: // example.swig %{ #include <iostream> #include <vector> using namespace std; int HelloWorld(char *str) { cout << "Hello World: " << str << endl; // run some slow code vector<int> array; for (int i=0; i < 10000000; i++) array.push_back(i*2); for (int i=0; i < array.size(); i++) array[i]++; return 0; } %} %module example int HelloWorld(char *str); Third, compile the code and load the exension: swig -c++ -php5 example.swig g++ `php-config --includes` -O2 -march=native -mtune=native -std=c++11 -fPIC -c *.cpp g++ -shared *.o -o exa