$ sed -i "s/^\exclude.*$/exclude=/g" /etc/yum.conf # allow kernel-devel package. $ yum groupinstall -y 'Development Tools' |
$ git clone http://git.php.net/repository/php-src.git |
$ ./buildconf $ ./configure --prefix=$HOME/php --disable-cgi --disable-all --enable-debug --enable-maintainer-zts $ make && make install |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function hello_world() { return "Hello, World!" ; } function hello( $name , $format = true) { if ( $format ) { $name = ucfirst( strtolower ( $name )); } return "Hello, " . $name . "!" ; } |
1 2 3 4 5 6 7 | PHP_ARG_ENABLE(hello, whether to enable hello support, [ - -enable -hello Enable hello support]) if test "$PHP_HELLO" = "yes" ; then AC_DEFINE(HAVE_HELLO, 1, [Whether you have hello]) PHP_NEW_EXTENSION(hello, hello.c, $ext_shared) fi |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #define PHP_MY_EXTENSION_VERSION "1.0" #define PHP_MY_EXTENSION_EXTNAME "hello" PHP_FUNCTION(hello_world); PHP_FUNCTION(hello); extern zend_module_entry hello_module_entry; #define phpext_my_extension_ptr &hello_module_entry static zend_function_entry hello_functions[] = { PHP_FE(hello_world, NULL) PHP_FE(hello, NULL) {NULL, NULL, NULL} }; zend_module_entry hello_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif PHP_MY_EXTENSION_EXTNAME, hello_functions, NULL, NULL, NULL, NULL, NULL, #if ZEND_MODULE_API_NO >= 20010901 PHP_MY_EXTENSION_VERSION, #endif STANDARD_MODULE_PROPERTIES }; ZEND_GET_MODULE(hello) PHP_FUNCTION(hello_world) { RETURN_STRING( "Hello, World!" , 1); } PHP_FUNCTION(hello) { char *name; size_t name_len; zend_bool *format = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b" , &name, &name_len, &format) == FAILURE) { RETURN_NULL(); } if (format && name_len) { name = estrndup(name, name_len); php_strtolower(name, name_len); *name = toupper (*name); } char *out; size_t out_len = spprintf(&out, 0, "Hello, %s!" , name); RETVAL_STRINGL(out, out_len, 0); if (format && name_len) { efree(name); } return ; } |
$ $HOME/php/bin/phpize $ ./configure --with-php-config=$HOME/php/bin/php-config $ make && make install |
$ $HOME/php/bin/php -dextension=hello.so -r "echo hello_world();" # Hello, World! $ $HOME/php/bin/php -dextension=hello.so -r "echo hello('PhP');" # Hello, Php! $ $HOME/php/bin/php -dextension=hello.so -r "echo hello('PhP', false);" # Hello, PhP! |
$ git clone https://github.com/CUBRID/cubrid-php.git |