apollo
apollo

Reputation: 353

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

Upvotes: 11

Views: 11052

Answers (3)

JWprogrammer
JWprogrammer

Reputation: 41

You should also consider using Zephir. Its syntax is very similar to PHP. It is specially designed to create PHP extensions and compiles into an extension.

There are even several converters from regular PHP to Zephir. They do not take into account all the peculiarities, so some minor code changes will be needed before compiling. I use sandrokeil/php-to-zephir.

Upvotes: 1

Book Of Zeus
Book Of Zeus

Reputation: 49867

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.

Upvotes: 10

fire
fire

Reputation: 21531

Rather than try and build an extension in C you should consider compiling your source code using HipHop instead. This will be much simpiler and run your code pretty fast.

Upvotes: 2

Related Questions