Httpcws.php
1.38 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
<?php
class Q_Ws_Adapter_Httpcws extends Q_Ws_Adapter_Abstract
{
private $server;
public function __construct(array $options)
{
$_options = array(
'mode' => Q_Server_Core::SERVER_MODE_PROXY,
'select' => Q_Server_Core::SERVER_SELECT_MODE_RAND
);
$options = $_options + $options;
$this->server = Q_Server::factory('search', 'words', 'servers', $options);
}
/**
* (non-PHPdoc)
* @see Q_Ws_Adapter_Abstract::getWords()
* @return array
*/
public function getWords($inputs)
{
if (strlen($inputs) <= 20480) {
$words = addslashes($inputs);
try {
$inputs = iconv('UTF-8', 'GBK//TRANSLIT', $words);
} catch (Exception $e) {
return array($words);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->server['host'] . ':' . $this->server['port']);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($inputs));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = iconv('GBK', 'UTF-8//TRANSLIT', curl_exec($ch));
curl_close($ch);
$result = empty($result) ? array() : array_filter(explode(' ', $result));
array_push($result, $words);
return $result;
} else {
return array();
}
}
}