PHP
Chilkat2 PHP
REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)
See more REST Examples
Demonstrates how the autoReconnect argument to the Connect method is used.Chilkat PHP Downloads
<?php
use Chilkat2\Rest;
use Chilkat2\Xml;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$rest = new Rest();
// This example demonstrates the usage of the autoReconnect argument to the Connect method.
// When autoReconnect is on, subsequent REST method calls will automatically re-connect
// if necessary, using the same information (domain/IP address, port number, and TLS).
$bTls = false;
$port = 80;
$bAutoReconnect = true;
$rest->Connect('dev.markitondemand.com', $port, $bTls, $bAutoReconnect);
// Get a stock quote:
$rest->AddQueryParam('symbol', 'AAPL');
try {
$responseXml = $rest->FullRequestNoBody('GET', '/MODApis/Api/v2/Quote');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$xml = new Xml();
$xml->LoadXml($responseXml);
echo 'AAPL LastPrice: ', $xml->GetChildContent('LastPrice'), "\n";
// Get another stock quote. If a new HTTP connection is required,
// the REST object will automatically connect using the same parameters.
$rest->AddQueryParam('symbol', 'AMZN');
try {
$responseXml = $rest->FullRequestNoBody('GET', '/MODApis/Api/v2/Quote');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$xml->LoadXml($responseXml);
echo 'AMZN LastPrice: ', $xml->GetChildContent('LastPrice'), "\n";