If you’re reading this tutorial, you probably have some interest in writing an extension for the PHP language. If not… well perhaps when we’re done you’ll have discovered an interest you didn’t know existed! - devzone.zend.com
If you have your PHP installed in a custom location, you need to add the bin directory to your PATH environment variable to avoid typing the full path. e.g. I have the bleeding edge PHP (PHP version 5.5.0) installed in /usr/local/php5/. To add the binaries to the $PATH,
export PATH=$PATH:/usr/local/php5/bin/
Preparing to Build the PHP Extension
Create a new directory for the new extension under source/ext. You need to create the following three files for a simple extension.
#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "upeksha.h"// list of custom PHP functions provided by this extension// set {NULL, NULL, NULL} as the last record to mark the end of liststaticzend_function_entryupeksha_functions[]={PHP_FE(say_name,NULL){NULL,NULL,NULL}};// the following code creates an entry for the module and registers it with Zend.zend_module_entryupeksha_extension_module_entry={STANDARD_MODULE_HEADER,PHP_UPEKSHA_EXTNAME,upeksha_functions,NULL,// name of the MINIT function or NULL if not applicableNULL,// name of the MSHUTDOWN function or NULL if not applicableNULL,// name of the RINIT function or NULL if not applicableNULL,// name of the RSHUTDOWN function or NULL if not applicableNULL,// name of the MINFO function or NULL if not applicablePHP_UPEKSHA_VERSION,STANDARD_MODULE_PROPERTIES};ZEND_GET_MODULE(upeksha_extension)// implementation of a custom say_name()PHP_FUNCTION(say_name){RETURN_STRING("Upeksha Wisidagama",1);}
Next run phpize in the same directory.
Making and Installing the Upeksha PHP Extension
run make. You’ll get a message, ‘Libraries have been installed in: /home/uw/Downloads/php-5.5.0/ext/uw/modules’.
Load the extension by adding the following line to the php.ini file.