forked from webvul/php-filter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_server.php
More file actions
executable file
·78 lines (55 loc) · 2 KB
/
Copy pathhttp_server.php
File metadata and controls
executable file
·78 lines (55 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* http://blog.41ms.com/post/41.html
*/
// 设置脚本最大运行内存,根据字典大小调整
ini_set('memory_limit', '2048M');
// 设置时区
date_default_timezone_set('Asia/Shanghai');
// 加载助手文件
require_once('FilterHelper.php');
// http服务绑定的ip及端口
$serv = new swoole_http_server("127.0.0.1", 9502);
$serv->set(array(
// 'daemonize' => 1,
'log_file' => '/tmp/swoole.log',
// 'user' => 'www',
// 'group' => 'www'
));
/**
* 处理请求
*/
$serv->on('Request', function($request, $response) {
xhprof_enable();
// 接收get请求参数
$content = isset($request->post['content']) ? $request->post['content']: '';
$arr_ret = array();
if (!empty($content)) {
// 字典树文件路径,默认当时目录下
$tree_file = 'blackword.tree';
// 清除文件状态缓存
clearstatcache();
// 获取请求时,字典树文件的修改时间
$new_mtime = filemtime($tree_file);
// 获取最新trie-tree对象
$trie = FilterHelper::get_trie($tree_file, $new_mtime);
// 执行查找敏感词
$stime = microtime(true);
$arr_ret['data'] = $trie->search_all($content);
$etime = microtime(true);
}
$arr_ret['time'] = sprintf('%01.6f', $etime-$stime);
$arr_ret['memory'] = (memory_get_peak_usage() / 1024 / 1024) . 'M';
$xhprof_data = xhprof_disable();
$XHPROF_ROOT = '/var/www/xhprof';
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
// 定义http服务信息及响应处理结果
$response->cookie("User", "W.Y.P");
$response->header("X-Server", "W.Y.P WebServer(Unix) (Red-Hat/Linux)");
$response->header('Content-Type', 'Content-Type: text/html; charset=utf-8');
$response->end(json_encode($arr_ret));
});
$serv->start();