Example #1
0
$oaConn = new OAConnection(new OAClientConfigIni('..'));
//var_dump($oaConn);
// The OAConnection takes a ClientConfig instance to get the APIKey and APIToken references.
// A default class that uses an INI file is provided.
// The default directory for the filename is the API installation folder
// The default filename is ./conf/connection.ini (which ought to be chmod 400 and owned by the application daemon user)
// Here's an example showing an INI Config file stored in the /etc/myapp/oaconf/connection_local.ini file
//$oaConn = new OAConnection( new OAClientConfigIni('/etc/myapp', '/conf/connection_local.ini') );
// Using this file requires no parameters to be passed in though it does
//$oaConn->setDebuglevel( 2 );
echo "Connecting to server..." . PHP_EOL;
$connected = '';
$attempts = 3;
while (!$connected and $attempts > 0) {
    try {
        echo "Connecting (" . $oaConn->endpointUrl() . "): {$attempts} remaining" . PHP_EOL;
        $oaConn->connect();
        $connected = $oaConn->isConnected();
        if ($connected) {
            echo "Successfully connected!" . PHP_EOL;
        }
    } catch (Exception $e) {
        //echo $response->error . PHP_EOL;
        echo $e->getMessage() . PHP_EOL;
    }
    $attempts = $attempts - 1;
}
if (!$connected) {
    exit("Failed to establish a connection with the OpenACH server.");
}
try {