简体   繁体   中英

“Failed to open stream: Permission denied” Connecting bitcoind with JSON-RPC PHP

I'm trying to control bitcoin daemon with PHP but I am having an issue when trying to connect to it.

I've followed these steps: en.bitcoin (dot) it/wiki/PHP_developer_intro

PHP code:

<?php
require_once 'jsonRPCClient.php';
$bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/');
echo "<pre>\n";
print_r($bitcoin->getinfo());
echo "</pre>";
?>

Bitcoind conf:

rpcuser=user
rpcpassword=password
server=1
daemon=1
listen=1

var/log/httpd/error_log:

[Tue Apr 06 15:47:15.403045 2015] [:error] [pid 2293] [client 10.0.0.34:50333] PHP Warning: fopen( http://...@127.0.0.1:8332/ ): failed to open stream: Permission denied in /var/www/html/jsonRPCClient.php on line 132 [Tue Apr 06 15:47:15.410993 2015] [:error] [pid 2293] [client 10.0.0.34:50333] PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://user:password@127.0.0.1:8332/ ' in /var/www/html/jsonRPCClient.php:140\\nStack trace:\\n#0 /var/www/html/bitcoin_get_info.php(15): jsonRPCClient->__call('getinfo', Array)\\n#1 /var/www/html/bitcoin_get_info.php(15): jsonRPCClient->getinfo()\\n#2 {main}\\n thrown in /var/www/html/jsonRPCClient.php on line 1406

Edit:

$ bitcoin-cli getinfo

Works fine, with PHP it doesn't

Maybe try adding rpcallowip=127.0.0.1 into your config and see what happens.

Also make sure that your bitcoind.conf is actually being used, to test this you can set the daemon to testnet using testnet=1 in bitcoind.conf . Restart your bitcoind server then do bitcoin-cli getinfo to see which network it's connected to. If the change isn't reflected then perhaps the bitcoind.conf file is in another location?

Also, make sure you restart your bitcoind server every time you make a change to the bitcoind.conf file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM