提交 a4dbaea4 编写于 作者: Y yuqing

support php extension

上级 ec4df419
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
......
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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <php.h>
#ifdef ZTS
#include "TSRM.h"
#endif
#include <SAPI.h>
#include <php_ini.h>
#include "ext/standard/info.h"
#include <zend_extensions.h>
#include <zend_exceptions.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#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<count; k++)
{
add_index_string(return_value, k, ip_addresses[k], 1);
}
}
#ifndef FASTCOMMON_H
#define FASTCOMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef PHP_WIN32
#define PHP_FASTDFS_API __declspec(dllexport)
#else
#define PHP_FASTDFS_API
#endif
PHP_MINIT_FUNCTION(fastcommon);
PHP_RINIT_FUNCTION(fastcommon);
PHP_MSHUTDOWN_FUNCTION(fastcommon);
PHP_RSHUTDOWN_FUNCTION(fastcommon);
PHP_MINFO_FUNCTION(fastcommon);
ZEND_FUNCTION(fastcommon_version);
#ifdef __cplusplus
}
#endif
#endif /* FASTCOMMON_H */
extension = fastcommon.so
Name: fastcommon
Version: 1.0.0
Release: 1%{?dist}
Summary: The php extension for libfastcommon
License: GPL
Group: Arch/Tech
URL: http://perso.orange.fr/sebastien.godard/
Source: http://perso.orange.fr/sebastien.godard/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libfastcommon >= 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<yuqing@yongche.com>
- first RPM release (1.0)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册