php yar页面输出样式是怎么实现的

2022-08-12 科技 55阅读
1、安装msgpack、yar、yaf三个php扩展

2、编译yar的时候,使用./configure --enable-msgpack --with-php-config=/usr/local/php/bin/pgp-config参数,--enable-msgpack参数是开启packager对yar的支持

3、php -i|grep msgpack,如果有yar.packager => msgpack => msgpack说明yar已经支持了msgpack

4、测试页面
class YarCheckKeyword {
protected static $HOSTNAME = 'kwdt.yarc.service.weibo.com';
protected static $PORT = '7002';

public function connectKwdt_Server($text, $return_text = 1, $types=array(1, 2, 3), $withoutsass = false) {
if (!class_exists("Yar_client") || !$text || !$types) {
return "yar_client no exists\n";
}
$funcname = "detect";
$host = YarCheckKeyword::$HOSTNAME;
$port = YarCheckKeyword::$PORT;
try{
$client = new Yar_Client("tcp://$host:$port");
$response = $client->$funcname($text, $return_text, $types);
return $response;
}catch (Exception $e){
print_r($e);
}
}
}
$text='aaaaaaaaaaa';
$obj=new YarCheckKeyword();
$a=$obj->connectKwdt_Server($text);
print_r($a);

5、上述代码保存成文件,使用php执行,测试结果为下面内容说明成功
Array
(
[0] => -1
[1] => no keyword occured
)
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com