Author

Topic: [Solved] Problem integrating daemon with PHP (Read 622 times)

full member
Activity: 154
Merit: 100
January 12, 2014, 02:33:54 PM
#4
Issue has been fixed
full member
Activity: 154
Merit: 100
Have you set the rpcport, rpcuser and rpcpassword in the .conf file? Also listen=1?

yes I did that but did not do listen=1 will do it right away and update if that works
newbie
Activity: 34
Merit: 0
Have you set the rpcport, rpcuser and rpcpassword in the .conf file? Also listen=1?
full member
Activity: 154
Merit: 100
This is solved now, if you want you can have a look on https://bitcointalksearch.org/topic/step-by-step-integrating-bitcoin-daemon-with-php-412425


So I have installed daemon of bicoin litecoin and dogecoin on the same server all three of them are up and running but bitcoin daemon does not reply anything when I run bitcoind getinfo may be network issues or something like that. I have installed php on the same server and created a index.php file in /var/www/ folder


content of index.php file :
Code:
include_once('Bitcoin.php');
include_once(
'jsonRPCClient.php');
$dogecoin = new jsonRPCClient('http://user:pass@localhost:8332/');
print_r($dogecoin->getinfo());
?>


content of Bitcoin.php :
Code:
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_RETURNTRANSFER1);
curl_setopt($curlCURLOPT_HTTPHEADER, Array("Content type:application/json"));
curl_setopt($curlCURLOPT_URL$this->url);
curl_setopt($curlCURLOPT_USERPWD$this->username.":".$this->password);
curl_setopt($curlCURLOPT_POSTTRUE);
curl_setopt($curlCURLOPT_POSTFIELDS$request);
$response curl_exec($curl);
curl_close($curl);

if(!
$resposne)
{
throw new 
Exception('Unable to connect to '.$this->url0);
}
$response json_decode($response,true);
}

then there are condition to throw different error upon different situation

}
Jump to: