A freelance software engineer with experience in webapplications, databases and bioinformatics.
A contributor to Parrot and the person behind Pipp.
A physicist who worked with third sound in Helium-III and CCD X-ray detectors.
barney on irc.perl.org
github: http://github.com/bschmalhofer [github.com]
XING: https://www.xing.com/profile/Bernhard_Schmalhofer [xing.com]
PHP Extensions are usually written C and they usually export at least one constant, function, class, resource type or stream to the PHP userspace. So they are pretty much the same as XS-Modules in Perl 5. Extensive information about PHP extension can be found in Sara Golemons book 'Extending and Embedding PHP'.
The several hundred standard functions of PHP are implemented in terms of extensions.
Pipp, http://pipp.org/, either needs to reimplement this massive count of functions, or support extensions natively.
Being lazy, native support for extensions is the way to go.
So let's see how to create a dummy PHP extension. The following is for Linux and is based on the tutorial http://devzone.zend.com/article/1021-Extension-Writing-Part-I-Introduction-to-P
The first step is to build PHP 5.3 with development support. The source can be checked out from a CVS repository. See http://www.php.net/anoncvs.php for details and the password for anonymous CVS access.
:pserver:firstname.lastname@example.org:/repository checkout -r PHP_5_3 php5
Buildconf performs some checks and creates a configure script for the GNU autotools. 're2c' is the parser generator used by PHP 5.3. It is not build dependency, as the generated C-files are in the repository. There is also a message about 'autotools 2.13' being recommended, but I simply ignore that.
For building extensions we need an installed PHP and it's associated helper scripts. Let's install our new PHP next to the source, so that the system PHP is left undisturbed.
./configure --prefix=/home/bernhard/first_php_extension/installed --enable-debug --enable-maintainer-zts --enable-embed
This should leave us with PHP 5.3 with debug support.
bernhard@heist:~/first_php_extension/php5$ php --version
PHP 5.3.0RC3-dev (cli) (built: Jun 7 2009 12:36:41) (DEBUG)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
The next step is to create a dummy extension without specific functionality. The helper script 'ext_skel' creates a stub in the directory 'pipp_sample'.
For now I leave pipp_sample.c alone, but config.m4 needs to be edited. Instructions can be found in config.m4 itself, I ended up with uncommenting the lines 16, 18, 60.
The helper phpize takes info from the PHP installation and creates more files, including a configure script.
Now the dummy extension can be configured and compiled.
A sanity test can be done with:
Now let's copy the generated shared lib for use by the installed PHP.
The shared library could also be load by Pipp. Let's take a look at the function.
/home/bernhard/first_php_extension/installed/lib/php/extensions/debug-zts-20090 115/pipp_sample.so | grep ' U '
The undefined functions are provided by the PHP extension API. These are also the functions that need to be implemented for Pipp.