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_connection.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 
19 // Default init
20 $connection = new \HCE\transport\Connection ();
21 
22 if (! $connection->error) {
23  echo 'Connection instance ' . var_export ( $connection->getConnectionArray (), true ) . PHP_EOL;
24 } else {
25  echo 'Error ' . $connection->error . ' create connection instance with default initialization' . PHP_EOL;
26  exit ( 1 );
27 }
28 
29 // Configured init
30 $connection = new \HCE\transport\Connection ( array (
31  'host' => 'localhost',
32  'port' => \HCE\transport\PROTOCOL_PORT_ADMIN_DEFAULT,
33  'type' =>\HCE\transport\PROTOCOL_CONNECTION_TYPE_ADMIN,
34  'identity' => \HCE\transport\IdGenerator::getClientId ()
35 ) );
36 if (! $connection->error) {
37  echo 'Connection instance ' . var_export ( $connection->getConnectionArray (), true ) . PHP_EOL;
38 } else {
39  echo 'Error ' . $connection->error . ' create connection instance with configured initialization' . PHP_EOL;
40  exit ( 1 );
41 }
42 
43 // Try to open connection
44 if ($connection->open ()) {
45  echo 'Connection opened' . PHP_EOL;
46  $connection->close ();
47  echo 'Connection closed' . PHP_EOL;
48 } else {
49  echo 'Error connection opene!' . PHP_EOL;
50 }
51 
52 ?>