public static function searchBySocket($queryString)
{
$result = false;
try {
$buffer = '';
$socket = stream_socket_client(Zend_Registry::get("searchSocket"), $errno, $errstr, 3);
if ($socket) {
fputs($socket, "$queryString/r/n");
while (!feof($socket)) {
$buffer .= fgets($socket, 4096);
}
fclose($socket);
if($buffer != 'Empty') {
require_once 'Zend/Json.php';
$result = Zend_Json::decode($buffer);
}
}
}
catch (Exception $e) {
}
return $result;
}
------------------------------------------------------
其中 $queryString是json字符串
Zend_Registry::get("searchSocket") eg: tcp://127.0.0.1:2008
{
$result = false;
try {
$buffer = '';
$socket = stream_socket_client(Zend_Registry::get("searchSocket"), $errno, $errstr, 3);
if ($socket) {
fputs($socket, "$queryString/r/n");
while (!feof($socket)) {
$buffer .= fgets($socket, 4096);
}
fclose($socket);
if($buffer != 'Empty') {
require_once 'Zend/Json.php';
$result = Zend_Json::decode($buffer);
}
}
}
catch (Exception $e) {
}
return $result;
}
------------------------------------------------------
其中 $queryString是json字符串
Zend_Registry::get("searchSocket") eg: tcp://127.0.0.1:2008