Creating a custom PHP extension (.so)

I have a high traffic site that does business in the US and Canada. We have many servers, but I want to make sure that it is 100% available without latency.

I found out about creating custom extensions (I know a little C) and I want to create custom validation / files (since php extensions are faster).

I don’t want to ask you for all new extensions, but I want to know the general idea of ​​how to build it (I use CentOS).

Example:

One section of our site is shipping tracking, and this requires a zip code.

For the USA, I have:

function check_usa_postal_code($pc) { return is_numeric($pc); } 

But for Canada, I would like to create a custom function in PHP, for example:

check_canada_postal_code($pc)

This function should return 1 or 0.

thanks

+7
source share
2 answers

I recommend reading the following articles:

Extension Writing Part I: Introduction to PHP and Zend

How to Create PHP Extensions - Part I: Simple Functions

and here is how to compile:

UNIX: building PHP extensions

Build PHP Extensions Using SWIG

(I recommend SWIG as mario said)

Learn more about Canadian postal codes in Canada's postal codes , as not all letters are used.

+9
source

Instead of trying to build a C extension, you should consider compiling the source code with HipHop . It will be a lot of simpiler and will quickly run your code.

+2
source

All Articles