diff --git a/HISTORY b/HISTORY index d92d5c0..d506883 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.13 2015-01-14 + * support php extension + Version 1.12 2014-12-05 * bug fixed: must check the return value of vsnprintf * can call sched_add_entries many times before schedule diff --git a/php-ext/config.m4 b/php-ext/config.m4 new file mode 100644 index 0000000..e102666 --- /dev/null +++ b/php-ext/config.m4 @@ -0,0 +1,20 @@ +dnl config.m4 for extension fastcommon + +PHP_ARG_WITH(fastcommon, wapper for libfastcommon +[ --with-fastcommon Include fastcommon wapper for libfastcommon]) + +if test "$PHP_FASTCOMMON" != "no"; then + PHP_SUBST(FASTCOMMON_SHARED_LIBADD) + + if test -z "$ROOT"; then + ROOT=/usr + fi + + PHP_ADD_INCLUDE($ROOT/include/fastcommon) + + PHP_ADD_LIBRARY_WITH_PATH(fastcommon, $ROOT/lib, FASTCOMMON_SHARED_LIBADD) + + PHP_NEW_EXTENSION(fastcommon, fastcommon.c, $ext_shared) + + CFLAGS="$CFLAGS -Wall" +fi diff --git a/php-ext/fastcommon.c b/php-ext/fastcommon.c new file mode 100644 index 0000000..2695ba1 --- /dev/null +++ b/php-ext/fastcommon.c @@ -0,0 +1,163 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include + +#ifdef ZTS +#include "TSRM.h" +#endif + +#include +#include +#include "ext/standard/info.h" +#include +#include +#include +#include +#include +#include +#include +#include "local_ip_func.h" +#include "logger.h" +#include "sockopt.h" +#include "fastcommon.h" + +#define MAJOR_VERSION 1 +#define MINOR_VERSION 0 + +#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) +const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 }; +#undef ZEND_BEGIN_ARG_INFO_EX +#define ZEND_BEGIN_ARG_INFO_EX(name, pass_rest_by_reference, return_reference, required_num_args) \ + static zend_arg_info name[] = { \ + { NULL, 0, NULL, 0, 0, 0, pass_rest_by_reference, return_reference, required_num_args }, +#endif + +// Every user visible function must have an entry in fastcommon_functions[]. + zend_function_entry fastcommon_functions[] = { + ZEND_FE(fastcommon_version, NULL) + {NULL, NULL, NULL} /* Must be the last line */ + }; + +zend_module_entry fastcommon_module_entry = { + STANDARD_MODULE_HEADER, + "fastcommon", + fastcommon_functions, + PHP_MINIT(fastcommon), + PHP_MSHUTDOWN(fastcommon), + NULL,//PHP_RINIT(fastcommon), + NULL,//PHP_RSHUTDOWN(fastcommon), + PHP_MINFO(fastcommon), + "1.00", + STANDARD_MODULE_PROPERTIES +}; + +#ifdef COMPILE_DL_FASTCOMMON + ZEND_GET_MODULE(fastcommon) +#endif + +PHP_MINIT_FUNCTION(fastcommon) +{ + log_init(); + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(fastcommon) +{ + log_destroy(); + return SUCCESS; +} + +PHP_RINIT_FUNCTION(fastcommon) +{ + return SUCCESS; +} + +PHP_RSHUTDOWN_FUNCTION(fastcommon) +{ + return SUCCESS; +} + +PHP_MINFO_FUNCTION(fastcommon) +{ + char mc_info[64]; + sprintf(mc_info, "fastcommon v%d.%02d support", + MAJOR_VERSION, MINOR_VERSION); + + php_info_print_table_start(); + php_info_print_table_header(2, mc_info, "enabled"); + php_info_print_table_end(); +} + +/* +string fastcommon_version() +return client library version +*/ +ZEND_FUNCTION(fastcommon_version) +{ + char szVersion[16]; + int len; + + len = sprintf(szVersion, "%d.%02d", + MAJOR_VERSION, MINOR_VERSION); + + RETURN_STRINGL(szVersion, len, 1); +} + +/* +array fastcommon_gethostaddrs([string if_alias_prefix]); +return false for fail, array for success +*/ +ZEND_FUNCTION(fastcommon_gethostaddrs) +{ + int argc; + char *if_alias_prefix; + int if_prefix_len; + int count; + int k; + int alias_count; + char ip_addresses[FAST_MAX_LOCAL_IP_ADDRS][IP_ADDRESS_SIZE]; + char *if_alias_prefixes[1]; + + argc = ZEND_NUM_ARGS(); + if (argc > 1) { + logError("file: "__FILE__", line: %d, " + "fastcommon_gethostaddrs parameters count: %d is invalid", + __LINE__, argc); + RETURN_BOOL(false); + } + + if_alias_prefix = NULL; + if (zend_parse_parameters(argc TSRMLS_CC, "|s", &if_alias_prefix, + &if_prefix_len) == FAILURE) + { + logError("file: "__FILE__", line: %d, " + "zend_parse_parameters fail!", __LINE__); + RETURN_BOOL(false); + } + + + if (if_alias_prefix == NULL || if_prefix_len == 0) + { + alias_count = 0; + if_alias_prefixes[0] = NULL; + } + else + { + alias_count = 1; + if_alias_prefixes[0] = if_alias_prefix; + } + + if (gethostaddrs(if_alias_prefixes, alias_count, ip_addresses, \ + FAST_MAX_LOCAL_IP_ADDRS, &count) != 0) + { + RETURN_BOOL(false); + } + + array_init(return_value); + for (k=0; k= 1.0.12 +Requires: libfastcommon >= 1.0.12 + +%description +This package provides the php extension for libfastcommon + +%prep +%setup -q + +%build +phpize +%configure +make + +%install +rm -rf %{buildroot} + +mkdir -p %{buildroot}/usr/lib64/php/modules +mkdir -p %{buildroot}/etc/php.d +cp -f .libs/fastcommon.so %{buildroot}/usr/lib64/php/modules/ +cp -f fastcommon.ini %{buildroot}/etc/php.d/fastcommon.ini.sample + +%post + +%preun + +%postun + +%clean +#rm -rf %{buildroot} + +%files +%defattr(-,root,root,-) +%{_libdir}/php/modules/* +/etc/php.d/* + +%changelog +* Jan 14 2015 Yu Qing +- first RPM release (1.0)