I'm able to connect to bitcoind using my command line and the process is running with the appropriate port but when I try to run it through XAMPP after using the JSON-RPC library (I used the PHP developer intro for the code) it's giving me the following error, and I don't know why:

Warning:  fopen(): Failed to enable crypto in /opt/lampp/htdocs/bitcoins/jsonRPCClient.php on line 132

Warning:  fopen(https://[email protected]:8332/): failed to open stream: operation failed in /opt/lampp/htdocs/bitcoins/jsonRPCClient.php on line 132
Fatal error:  Uncaught exception 'Exception' with message 'Unable to connect to https://user:password
@' in /opt/lampp/htdocs/bitcoins/jsonRPCClient.php:140
Stack trace:
#0 /opt/lampp/htdocs/bitcoins/testServer.php(7): jsonRPCClient->__call('getinfo', Array)
#1 /opt/lampp/htdocs/bitcoins/testServer.php(7): jsonRPCClient->getinfo()
#2 {main}
  thrown in /opt/lampp/htdocs/bitcoins/jsonRPCClient.php on line 140

The code is the following: (we tried toggling between http and https and it's still not working)

require_once 'jsonRPCClient.php';

$bitcoin = new jsonRPCClient('https://user:[email protected]:8332/');

echo "<pre>\n";
echo "</pre>";
  • are you sure you are providing the right login/password? Oct 20, 2013 at 22:10
  • @SalvadorDali: I copied and pasted it from bitcoin.conf, also tried shifting the hosting to Amazon EC2 and it totally didn't work.
    – Vinamrata
    Oct 21, 2013 at 2:57

5 Answers 5


As @Bittylicious mentioned the JSON-RPC is a little bit buggy


Note: The jsonRPCClient library uses fopen() and will throw an exception saying "Unable to connect" if it receives a 404 or 500 error from bitcoind. This prevents you from being able to see error messages generated by bitcoind (as they are sent with status 404 or 500).

You have an option use EasyBitcoin instead, that will throw more accurate error messages and its pretty much the same than JSON-RPC

 require_once 'YOUR_FOLDER/easybitcoin.php';
 $rpc_host = 'YOUR_IP';
 $rpc_port = 'YOUR_PORT';
 $rpc_user = 'YOUR_USER';
 $rpc_pass = 'YOUR_KEY';
 $bitcoin = new Bitcoin($rpc_user, $rpc_pass, $rpc_host, $rpc_port);
 print_r($bitcoin->listreceivedbyaddress(0, true));

Hope this helps!


By default, bitcoind RPC goes over http, not https. Unless of course you enabled SSL by generating an SSL key and setting the required config option...


Otherwise, This line:

$bitcoin = new jsonRPCClient('https://user:[email protected]:8332/');

Should be changed to:

$bitcoin = new jsonRPCClient('http://user:[email protected]:8332/');

If that doesn't answer it let me know. There are a few other ways around it.

Welcome to the world of crystallographic currencies based on the satoshi client!

I think this little piece of info should be posted pretty inappropriately, it's hidden in documentation no one reads.


I resolved this problem by passing -rpcthreads=16 even though the VPS server is a single core


Just to add some useful information.

The jsonRPCClient does not return any useful information on errors, and all errors will just return the could not connect message. This is because bitcoind returns a HTTP error status code that's not 2xx. This is awful for debugging.

I have made a few hacky changes to the jsonRPCClient to get around this. What you need to do is:

  1. Add *'ignore_errors' => true* to the $opts array
  2. Change the error line that throws Request error to read throw new Exception('Request error: '.$response['error']['code'].' - '.$response['error']['message']);.

The latter change inparticular makes the jsonRPCClient specific to bitcoind, but it shouldn't be assuming that error is a string anyway.


Testnet connects on port 18332 unless you specify set the port in your conf file. Changing it to that should correct the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.