1
I have installed the daemons of Bitcoin, Litecoin and Dogecoin on the same server. All three of them are up and running, but the Bitcoin daemon does not reply with anything when I run bitcoind getinfo. It may be network issues or something like that. I have installed PHP on the same server and created an index.php file in the /var/www/ folder.
Content of index.php file:
<?php
include_once('Bitcoin.php');
include_once('jsonRPCClient.php');
$dogecoin = new jsonRPCClient('http://user:pass@localhost:8332/');
print_r($dogecoin->getinfo());
?>
Content of Bitcoin.php:
<?php
class Bitcoin (
// @var string
private $username;
// @var string
private @password;
// @var string
private $url;
// @var string
private $id;
public function __construct($url,$username,$password)
{
$this->url=$url;
$this->username = $username;
$this->password = $password;
$this->id = 1;
}
public function __call($method,$params)
{
$params = array_values($params);
$request = json_encode(array(
'method' =>strtolower($method),
'params' => $params,
'id' => $this-> id));
$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content type:application/json"));
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_USERPWD, $this->username.":".$this->password);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($curl);
curl_close($curl);
if(!$resposne)
{
throw new Exception('Unable to connect to '.$this->url, 0);
}
$response = json_decode($response,true);
}
Then there are a condition to throw a different error upon a different situation.
}
@peter-mortensen that extra lines are just to avoid typing all the exceptions it was not like this in the actual file – Khan Shahrukh – 2014-01-12T17:55:59.580