4. PHP Extension
(Zend Engine)
• PHP language written in C
• PHP interpreter written in C too
• And PHP Extension must written in C
• Another PHP implement may be using diffrence language
5. Why and When need
PHP extension ?
1. Buildin PHP function are not enough
2. Existing PHP extension are not enough
3. Pure PHP function are more slow
4. Have C lib can do this for you
6. Prepare
1. Ubuntu Linux
2. GNU C Compiler , build , make utils
3. PHP 5 Dev package : sudo apt-get install php5-dev
4. PHP source code
o sudo svn checkout http://svn.php.net/viewvc/php/php-
src/trunk
o
16. Edit C source file
- pre declare
const zend_function_entry simhash_functions[] = {
PHP_FE(confirm_hello_compiled, NULL) /* For testing,
remove later. */
PHP_FE(hello, NULL)
{NULL, NULL, NULL} /* Must be the last line in
hello_functions[] */
};
24. Return value (macro)
RETURN_LONG() for integer values
RETURN_DOUBLE() for floating point values
RETURN_BOOL() for true/false values
RETURN_NULL() for null value
.....
26. Anti Memory leak
• In C, memory management always very hard .
• Wrapper functions provides you with a safety net and some
helpful debugging facilities
• But convert existing C source can't use wrapper functions