I am using PHP to connect via CURL to the ledger and to test my connection am using the following script
<?php
$daemon = 'http://xxxxxxx:8443'; // default port 5005
function server($daemon) {
/////////// check server info
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $daemon);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '
{ "method" : "server_info", "params" : [ {}] }
');
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
if (empty($result)) {
throw new Exception("Content is empty.");
}
$obj = json_decode($result, 1);
if (empty($obj)) {
throw new Exception("JSON decode failed, content: " .$result);
}
return $obj;
}
$server = server($daemon);
var_dump($server);
?>
A successful connection will bring a result such as below
array(1) {
["result"]=>
array(2) {
["info"]=>
array(18) {
["build_version"]=>
string(7) "4.0.5-4"
["complete_ledgers"]=>
string(8) "1-191613"
["crn_activated"]=>
bool(true)
["crn_domain_name"]=>
string(10) "xxx.xxxxxxx.xxx"
["crn_public_key"]=>
string(52) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
["hostid"]=>
string(3) "csc"
["io_latency_ms"]=>
int(1)
["last_close"]=>
array(2) {
["converge_time_s"]=>
float(1.998)
["proposers"]=>
int(8)
}
["load"]=>
array(2) {
["job_types"]=>
array(2) {
[0]=>
array(2) {
["in_progress"]=>
int(1)
["job_type"]=>
string(13) "clientCommand"
}
[1]=>
array(2) {
["job_type"]=>
string(11) "peerCommand"
["per_second"]=>
int(15)
}
}
["threads"]=>
int(4)
}
["load_factor"]=>
int(1)
["peers"]=>
int(36)
["pubkey_node"]=>
string(52) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
["pubkey_validator"]=>
string(4) "none"
["server_state"]=>
string(4) "full"
["state_accounting"]=>
array(5) {
["connected"]=>
array(2) {
["duration_us"]=>
string(8) "38004520"
["transitions"]=>
int(1)
}
["disconnected"]=>
array(2) {
["duration_us"]=>
string(7) "1136881"
["transitions"]=>
int(1)
}
["full"]=>
array(2) {
["duration_us"]=>
string(12) "222333000321"
["transitions"]=>
int(1)
}
["syncing"]=>
array(2) {
["duration_us"]=>
string(9) "111007130"
["transitions"]=>
int(1)
}
["tracking"]=>
array(2) {
["duration_us"]=>
string(2) "83"
["transitions"]=>
int(1)
}
}
["uptime"]=>
int(222483)
["validated_ledger"]=>
array(6) {
["age"]=>
int(127)
["base_fee_csc"]=>
float(0.25)
["hash"]=>
string(64) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
["reserve_base_csc"]=>
int(10)
["reserve_inc_csc"]=>
int(1)
["seq"]=>
int(191613)
}
["validation_quorum"]=>
int(6)
}
["status"]=>
string(7) "success"
}
}