入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

php7安装扩展trie_filter,过滤敏感词

创建时间:2017-12-26 投稿人: 浏览次数:680

安装libdatrie

下载地址:https://linux.thai.net/~thep/datrie/datrie.html#Download
直接编译提示

[root@localhost libdatrie-0.2.4]# ./configure
...
libtool: link: gcc -g -O2 -o .libs/trietool-0.2 trietool.o  ../datrie/.libs/libdatrie.so
trietool.o: In function `conv_from_alpha":
/usr/local/src/libdatrie-0.2.4/tools/trietool.c:170: undefined reference to `libiconv"
trietool.o: In function `conv_to_alpha.isra.2.constprop.7":
trietool.c:(.text+0x181): undefined reference to `libiconv"

[root@localhost libdatrie-0.2.4]# whereis libiconv
libiconv: /usr/local/lib/libiconv.so /usr/local/lib/libiconv.la /usr/local/lib/libiconv.a
[root@localhost libdatrie-0.2.4]# 

可以看到系统是安装了libiconv的,可以肯定是路径引用不对,查看安装帮助

[root@localhost libdatrie-0.2.4]# ./configure -h
...
Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

Use these variables to override the choices made by `configure" or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <thep@linux.thai.net>.

解决方案:

[root@localhost libdatrie-0.2.4]# ./configure LDFLAGS=-L/usr/local/lib LIBS=-liconv

安装扩展

下载地址:https://github.com/wulijun/php-ext-trie-filter

[root@localhost php-ext-trie-filter]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-trie_filter=/usr/local/lib
[root@localhost php-ext-trie-filter]# make && make install
/usr/local/src/php-ext-trie-filter/trie_filter.c:82:34: error: unknown type name ‘zend_rsrc_list_entry’
 static void php_trie_filter_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
                                  ^
...
...
In file included from /usr/local/php/include/php/Zend/zend_API.h:28:0,
                 from /usr/local/php/include/php/main/php.h:39,
                 from /usr/local/src/php-ext-trie-filter/trie_filter.c:25:
/usr/local/php/include/php/Zend/zend_list.h:59:14: note: expected ‘struct zend_resource *’ but argument is of type ‘int’
 ZEND_API int zend_list_delete(zend_resource *res);
              ^
make: *** [trie_filter.lo] Error 1

参考:http://blog.csdn.net/xiaoai5324/article/details/62422779

PHP7版本问题,貌似要修改源码了。搜索了一圈,发现已经有人commit到了项目里面。

下载下来,直接复制过来替换掉,重新安装

[root@localhost php-ext-trie-filter]# make clean
[root@localhost php-ext-trie-filter]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-trie_filter=/usr/local/lib
[root@localhost php-ext-trie-filter]# make && make install
...
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don"t forget to run "make test".

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/

安装成功,感谢作者和大神们,拯救了我们这些小白。

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。