To use your new extension, you will have to execute the following steps:
1. $$ cd .. 2. $$ vi ext/myphpext/config.m4 3. $$ ./buildconf 4. $$ ./configure --[with|enable]-myphpext 5. $$ make 6. $$ ./php -f ext/myphpext/myphpext.php 7. $$ vi ext/myphpext/myphpext.c 8. $$ make
Repeat steps 3-6 until you are satisfied with ext/myphpext/config.m4 and step 6 confirms that your module is compiled into PHP. Then, start writing code and repeat the last two steps as often as necessary.
/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */
PHP_FUNCTION(confirm_myphpext_compiled); /* For testing, remove later. */ PHP_FUNCTION(HelloPHP);
/* Declare any global variables you may need between the BEGIN and END macros here:
ZEND_BEGIN_MODULE_GLOBALS(myphpext) long global_value; char *global_string; ZEND_END_MODULE_GLOBALS(myphpext) */
/* In every utility function you add that needs to use variables in php_myphpext_globals, call TSRMLS_FETCH(); after declaring other variables used by that function, or better yet, pass in TSRMLS_CC after the last function argument and declare your utility function with TSRMLS_DC after the last declared argument. Always refer to the globals in your function as MYPHPEXT_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */
/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */
/* If you declare any globals in php_myphpext.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(myphpext) */
/* True global resources - no need for thread safety here */ static int le_myphpext;
/* {{{ myphpext_functions[] * * Every user visible function must have an entry in myphpext_functions[]. */ zend_function_entry myphpext_functions[] = { PHP_FE(confirm_myphpext_compiled, NULL) /* For testing, remove later. */ PHP_FE(HelloPHP, NULL) {NULL, NULL, NULL} /* Must be the last line in myphpext_functions[] */ }; /* }}} */
/* {{{ myphpext_module_entry */ zend_module_entry myphpext_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "myphpext", myphpext_functions, PHP_MINIT(myphpext), PHP_MSHUTDOWN(myphpext), PHP_RINIT(myphpext), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(myphpext), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(myphpext), #if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; /* }}} */
/* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() STD_PHP_INI_ENTRY("myphpext.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_myphpext_globals, myphpext_globals) STD_PHP_INI_ENTRY("myphpext.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_myphpext_globals, myphpext_globals) PHP_INI_END() */ /* }}} */
/* {{{ php_myphpext_init_globals */ /* Uncomment this function if you have INI entries static void php_myphpext_init_globals(zend_myphpext_globals *myphpext_globals) { myphpext_globals->global_value = 0; myphpext_globals->global_string = NULL; } */ /* }}} */
/* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(myphpext) { /* If you have INI entries, uncomment these lines REGISTER_INI_ENTRIES(); */ return SUCCESS; } /* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(myphpext) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } /* }}} */
/* Remove if there's nothing to do at request start */ /* {{{ PHP_RINIT_FUNCTION */ PHP_RINIT_FUNCTION(myphpext) { return SUCCESS; } /* }}} */
/* Remove if there's nothing to do at request end */ /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(myphpext) { return SUCCESS; } /* }}} */
/* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* }}} */
/* Remove the following function when you have succesfully modified config.m4 so that your module can be compiled into PHP, it exists only for testing purposes. */
/* Every user-visible function in PHP should document itself in the source */ /* {{{ proto string confirm_myphpext_compiled(string arg) Return a string to confirm that the module is compiled in */ PHP_FUNCTION(confirm_myphpext_compiled) { char *arg = NULL; int arg_len, len; char *strg;
len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "myphpext", arg); RETURN_STRINGL(strg, len, 0); }
/* }}} */ /* The previous line is meant for vim and emacs, so it can correctly fold and unfold functions in source code. See the corresponding marks just before function definition, where the functions purpose is also documented. Please follow this convention for the convenience of others editing your code. */