HCE Project PHP language client API bindings  1.5.1
Hierarchical Cluster Engine PHP Client Interface API
 All Classes Namespaces Files Functions Variables Pages
search.php
Go to the documentation of this file.
1 #!/usr/bin/php
2 <?php
15 //Set default timezone if not set in host environment
16 @date_default_timezone_set(@date_default_timezone_get());
17 
18 require_once '../inc/hce_node_api.inc.php';
19 require_once '../inc/search.ini.php';
20 
21 $hce_connection=hce_connection_create(array('host'=>$Connection_host, 'port'=>$Connection_port, 'type'=>HCE_CONNECTION_TYPE_ROUTER, 'identity'=>$Client_Identity));
22 
23 if(!$hce_connection['error']){
24  if($LOG_MODE!=3){
25  echo 'Client ['.$Client_Identity.'] conected, start to send '.$MAX_QUERIES.' message requests...'.PHP_EOL.PHP_EOL;
26  }
27 
28  $t=time();
29  $Timedout=0;
30 
31  for($i=1; $i<=$MAX_QUERIES; $i++){
32  //$Request_Id=uniqid('ID-'.$i.'-'.date('H:i:s').'-', TRUE);
33  $Request_Id=hce_unique_message_id(1, $i.'-'.date('H:i:s').'-');
34  $msg_fields=array('id'=>$Request_Id, 'body'=>$Request_body, 'route'=>$Route);
35  hce_message_send($hce_connection, $msg_fields);
36 
37  if($LOG_MODE!=3){
38  echo 'request message '.$i.' ['.$Request_Id.'] sent...'.PHP_EOL;
39  }
40 
42  if($hce_responses['error']===0){
43  foreach($hce_responses['messages'] as $hce_message){
44  //var_dump($hce_message);
45  if($LOG_MODE==3){
46  echo $hce_message['body'];
47  }else{
48  $rjson=hce_sphinx_search_parse_json($hce_message['body']);
49  if($LOG_MODE!=0){
50  echo 'Message: id=['.$hce_message['id'].'], body=['.$hce_message['body'].']'.PHP_EOL;
51  }
52  if($LOG_MODE==4){
53  echo var_export($rjson, true).PHP_EOL;
54  }
55  $DocumentsNumber=hce_sphinx_search_result_get($rjson, HCE_SPHINX_SEARCH_RESULTS_MI);
56  echo 'Documents:'.$DocumentsNumber=hce_sphinx_search_result_get($rjson, HCE_SPHINX_SEARCH_RESULTS_MI).PHP_EOL;
57  }
58  }
59  }else{
60  if($hce_responses['error']==HCE_PROTOCOL_ERROR_TIMEOUT){
61  $Timedout++;
62  if($LOG_MODE!=3){
63  echo 'request timeout'.PHP_EOL;
64  }
65  }else{
66  if($LOG_MODE!=3){
67  echo 'request unknown error'.PHP_EOL;
68  }
69  }
70  }
71 
72  if($REQUEST_DELAY>0){
73  sleep($REQUEST_DELAY);
74  }
75  }
76 
78  if($LOG_MODE!=3){
79  echo PHP_EOL.'Finished '.$MAX_QUERIES.' queries, '.(time()-$t).' sec, '.floor($MAX_QUERIES/(time()-$t+0.00001)).' rps, '.$Timedout.' timedout'.PHP_EOL;
80  }
81 }else{
82  if($LOG_MODE!=3){
83  echo 'Connection create error '.$hce_connection['error'].PHP_EOL;
84  }else{
85  echo json_encode(array('data'=>array('match_info'=>array(), 'word_info'=>array(), 'doc_info'=>array())));
86  }
87 }
88 
89 exit();
90 
91 ?>