Resources on how to write your own PHP extension
Posted in development on November 18th, 2009 by Pedro Padron – Be the first to commentA few days ago I started to write my first PHP extension, and I have to admit it was a pain in the beginning. Actually it still is, but I’m the one to blame for lacking some C skills. Anyway, my advice is: if you want to write your own extension you’d better have a good reason to do so. Here are some of the most common ones:
- increase performance
- change PHP behavior (take a look at these PECL extensions)
- wrap a C library
- you are very curious and want to know how to do it anyway
If you still want to give it a try, here are some of the things that helped me along the way:
- Extending and Embedding PHP – THE book on extension development by Sara Golemon
- this article at Zend Devzone also by Sara Golemon
- PECL SVN tree is also a good start. It’s a good way to learn from real-life examples. The solr and mongo extensions are nice references for object oriented code. Some other easier-to-read extensions are selinux and zip. Checkout the code and mess with it.
- the PHP cross-referenced source code is the easiest way to browse through PHP source (including the Zend Engine and PECL extensions)
Maybe I’ll write some posts about this. Maybe.




