HCE Project PHP language client API bindings OOP style  1.1.1
Hierarchical Cluster Engine PHP Client Interface API OOP style
 All Classes Namespaces Files Functions Variables Pages
test_transport_request.php
Go to the documentation of this file.
1 <?php
14 // Set default timezone if not set in host environment
15 @date_default_timezone_set ( @date_default_timezone_get () );
16 
17 require_once 'hce/transport/Connection.inc.php';
18 require_once 'hce/transport/Request.inc.php';
19 require_once 'hce/transport/Constants.inc.php';
20 
21 require_once 'hce/admin/Constants.inc.php';
22 
23 // Simple admin command ECHO
24 $messageBody = 'Admin' . HCE\admin\CMD_DELIMITER . 'ECHO' . HCE\admin\CMD_DELIMITER . '' . HCE\admin\CMD_DELIMITER;
25 
26 // Create connection with default initialization
27 $connection = new \HCE\transport\Connection ();
28 if (! $connection->error) {
29  echo 'Connection created' . PHP_EOL;
30  // Create request with default initialization
31  $request = new \HCE\transport\Request ( $connection );
32  if (! $request->getErrorCode ()) {
33  echo 'Request created' . PHP_EOL;
34  // Try to open connection
35  if ($connection->open ()) {
36  // Execute request
37  $response = $request->execute ( $messageBody );
38  echo 'Request executed' . PHP_EOL;
39  // Close connection
40  $connection->close ();
41  // Check state
42  if ($response->getErrorCode ()) {
43  echo 'Error ' . $response->getErrorCode () . ' of request execution!' . PHP_EOL;
44  }
45  // Out result object
46  if ($response->getErrorCode () == \HCE\transport\PROTOCOL_ERROR_OK || $response->getErrorCode () == \HCE\transport\PROTOCOL_ERROR_WRONG_RESPONSE_MSG_ID) {
47  echo 'Response instance: ' . var_export ( $response, true ) . PHP_EOL;
48  }
49  } else {
50  echo 'Error open connection!' . PHP_EOL;
51  }
52  } else {
53  echo 'Error ' . $request->error . ' create request instance with default initialization!' . PHP_EOL;
54  exit ( 1 );
55  }
56 } else {
57  echo 'Error ' . $connection->error . ' create connection instance with default initialization!' . PHP_EOL;
58  exit ( 1 );
59 }
60 
61 ?>