Skip to content
Advertisement

Building custom PHP extension (.so)

I own a high traffic website that does business in the USA and Canada. We have lots of servers but I want to make sure it’s 100% available with no latency whatsoever.

I’ve learned about creating custom extensions (I know a little C) and I want to create custom validation/files (since php extensions runs faster).

I don’t want to ask for all new extensions from you guys but I want to know the general idea on how to build it (I am using CentOS).

Example:

One section of our site is the shipping tracking and this require a postal code.

For the USA I have:

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

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

check_canada_postal_code($pc)

This function should return 1 or 0.

Thanks

Advertisement

Answer

I recommend to read this article:

Extension Writing Part I: Introduction to PHP and Zend

and here’s how to compile:

UNIX: Compiling PHP Extensions

Build PHP extensions with SWIG

(I recommend SWIG like mario said)

Read more on Canadian zip codes at Postal codes in Canada since not all letters are being used.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement