安装php扩展trie_filter


php扩展trie_filter是一个用来在项目中需要对用户传递过来的文字进行过滤敏感词

安装基础类库

关键词过滤扩展,用于检查一段文本中是否出现敏感词,基于Double-Array Trie 树实现
安装 libdatrie , 需要 libdatrie-0.2.4 或更新的版本
它依赖 libiconv .

1 安装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 

中间问题
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/src/zabbix-2.4.7/libiconv-1.14/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib' make: *** [all] Error 2

  解决方法
    vim libiconv-1.14/srclib/stdio.in.h
    将689行代码:_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

2.安装libdatrie
 
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 

安装PHP扩展

  一般安装扩展时需要使用phpize进行设置配置
  如果没有需要 apt-get install php-dev
  我的是php7.2 所以需要apt-get install php7.2-dev
  源代码只兼容到5.3,然后又找到了新的包 https://github.com/zzjin/php-ext-trie-filter/tree/php7

 

 

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

php查找方法whereis php-config



配置

 

这个时候需要配置一下fpm和cli
vim /etc/php/7.2/cli/php.ini
再最后一行加入

 
[trie_filter] extension=trie_filter.so 
 

fpm相同操作

 

service php7.2-fpm restart 重启php

 

然后再使用php -m查看扩展

 

 

 


 

 
 



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM