Page 1 of 1

How to create PHP extension ?

Posted: Wed Oct 30, 2002 5:52 am
by iceberg
Hi,
I want to write an independent extension for PHP. This extension should not be compiled into PHP. It should be dynamically loaded in PHP script.
The platform is to be Linux. Can someone tell me the broad steps to do so ?

Thanks in advance,
iceberg.

Posted: Wed Oct 30, 2002 8:36 am
by mydimension
here is a good Table of Contents to get you going: http://www.php.net/manual/en/zend.php

Posted: Wed Oct 30, 2002 11:16 am
by volka
there are several modules within the source-distribution of php.
Take a look at those that can be configured via with-xyz-shared.
i.e. the tokenizer module. note:

Code: Select all

/* {{{ tokenizer_functionsї]
 *
 * Every user visible function must have an entry in tokenizer_functionsї].
 */
function_entry tokenizer_functionsї] = {
	PHP_FE(token_get_all,	NULL)
	PHP_FE(token_name,	NULL)
	{NULL, NULL, NULL}	/* Must be the last line in tokenizer_functionsї] */
};
/* }}} */

/* {{{ tokenizer_module_entry
 */
zend_module_entry tokenizer_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
	STANDARD_MODULE_HEADER,
#endif
	"tokenizer",
	tokenizer_functions,
	PHP_MINIT(tokenizer),
	PHP_MSHUTDOWN(tokenizer),
	PHP_RINIT(tokenizer),		/* Replace with NULL if there's nothing to do at request start */
	PHP_RSHUTDOWN(tokenizer),	/* Replace with NULL if there's nothing to do at request end */
	PHP_MINFO(tokenizer),
#if ZEND_MODULE_API_NO >= 20010901
	"0.1", /* Replace with version number for your extension */
#endif
	STANDARD_MODULE_PROPERTIES
};
/* }}} */

#ifdef COMPILE_DL_TOKENIZER
ZEND_GET_MODULE(tokenizer)
#endifif
in tokenizer.c

it worked

Posted: Thu Oct 31, 2002 7:31 am
by iceberg
thanks a lot. using the shared flag worked. it was the only missing thing.