php-ext-trie-filter 过滤关键词 不指定

jed , 2016-11-6 22:11 , 服务器技术 , 评论(0) , 阅读(38862) , Via 本站原创 | |
安装 libdatrie , 需要 libdatrie-0.2.4 或更新的版本

它依赖 libiconv .
安装:
================================

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure
make && make install

libdatrie 下载地址:
http://linux.thai.net/~thep/datrie/datrie.html#Download

安装:
================================

wget ftp://linux.thai.net/pub/ThaiLinux/software/libthai/libdatrie-0.2.4.tar.gz
tar -zxf libdatrie-0.2.4.tar.gz
cd libdatrie-0.2.4

./configure --prefix=/usr/local/libdatrie/
make ICONV_LIBS='/usr/local/lib/libiconv.so'
make install


编译出现错误 trietool.c:125: undefined reference to `libiconv'
解决办法为:./configure LDFLAGS=-L/usr/local/lib LIBS=-liconv

安装 PHP 扩展
================================

wget https://github.com/wulijun/php-ext-trie-filter/archive/master.zip
unzip master.zip
cd php-ext-trie-filter-master/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-trie_filter=/usr/local/libdatrie/
make && make install

将生成的 trie_filter.so 文件复制到 php 扩展目录,并在 php.ini 中添加该文件

修改 php.ini 文件,添加 trie_filter 扩展:extension=trie_filter.so,重启PHP。
   查看phpinfo发现trie_filter 扩展可用,如下图所示:
点击在新窗口中浏览此图片


https://github.com/wulijun/php-ext-trie-filter

=============遇到的问题===============
安装libiconv如果遇到下面的问题:

In file included from progname.c:26:0:
./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
 ^
make[2]: *** [progname.o] Error 1
make[2]: Leaving directory `/usr/local/directadmin/custombuild/libiconv-1.14/srclib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/local/directadmin/custombuild/libiconv-1.14/srclib'
make: *** [all] Error 2



解决方案:

cd /tmp/libiconv-1.14/srclib
vim stdio.in.h


找到这行内容:

_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

替换成:

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif


注意:结尾的#endif也要包括。


安装PHP如果遇到下面的问题:

/usr/include/stdio.h:325:14: note: expected ‘size_t *’ but argument is of type ‘zend_size_t *’
extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
              ^
/root/soft/soft/php-ext-trie-filter/trie_filter.c:566:27: error: macro "RETVAL_STRINGL" requires 3 arguments, but only 2 given
     RETVAL_STRINGL(p, plen);
                           ^
/root/soft/soft/php-ext-trie-filter/trie_filter.c:566:5: error: ‘RETVAL_STRINGL’ undeclared (first use in this function)
     RETVAL_STRINGL(p, plen);
     ^


解决方案:

vi php-ext-trie-filter/trie_filter.c


修改:

RETVAL_STRINGL(p, plen);
中PHP7这个宏定义只需要两个参数,
而PHP5需要三个

#if PHP_MAJOR_VERSION < 7
    RETVAL_STRINGL(p, plen,0);
#else
    RETVAL_STRINGL(p, plen);
#endif
解决


发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]