$ 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 |
function hello_world()
{
return "Hello, World!";
}
function hello($name, $format = true)
{
if ($format) {
$name = ucfirst(strtolower($name));
}
return "Hello, " . $name . "!";
}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
#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 |