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