2

I try to follow this PHP developer intro for bitcoin https://en.bitcoin.it/wiki/PHP_developer_intro

I make this steps on virtual dedicated server and everything works fine. But when I tried to perform the same steps on my virtual machine with OS fedora 14, the example from the article gives me an error:

Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://user:123456@127.0.0.1:8332/' in /var/www/html/jsonRPCClient.php:140
Stack trace:
#0 /var/www/html/btc.php(7): jsonRPCClient->__call('getbalance', Array)
#1 /var/www/html/btc.php(7): jsonRPCClient->getbalance()
#2 {main}
  thrown in /var/www/html/jsonRPCClient.php on line 140

the code is:

<?php
require_once 'jsonRPCClient.php';

$bitcoin = new jsonRPCClient('http://user:123456@127.0.0.1:8332/');

echo "<pre>\n";
print_r($bitcoin->getbalance());
echo "</pre>";
?>

when I execute ./bitcoind getbalance or ./bitcoind getinfo in command line, I get answer, but php script doesn't work.

netstat gives me the following:

[root@vitaly 32]# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 *:mysql                     *:*                         LISTEN      1297/mysqld         
tcp        0      0 localhost.localdomain:8332  *:*                         LISTEN      2171/bitcoind       
tcp        0      0 *:8333                      *:*                         LISTEN      2171/bitcoind       
tcp        0      0 localhost.localdomain:ipp   *:*                         LISTEN      1000/cupsd          
tcp        0      0 localhost.localdomain:smtp  *:*                         LISTEN      1337/sendmail: acce 
tcp        0      0 vitaly:39994                irc.lfnet.org:ircu-3        ESTABLISHED 2171/bitcoind       
tcp        0      0 vitaly:50594                c-98-207-155-236.hsd1.:8333 ESTABLISHED 2171/bitcoind       
tcp        0      0 vitaly:57654                c-67-170-81-79.hsd1.wa:8333 ESTABLISHED 2171/bitcoind       
tcp        0      0 localhost.localdomain:40427 localhost.localdomain:http  TIME_WAIT   -                   
tcp        0      0 vitaly:57486                ip72-193-65-74.lv.lv.c:8333 ESTABLISHED 2171/bitcoind       
tcp        0      0 vitaly:56222                109.254.91.55:8333          ESTABLISHED 2171/bitcoind       
tcp        1      0 vitaly:47205                stackoverflow.com:http      CLOSE_WAIT  2016/firefox        
tcp        0      0 vitaly:59602                pool-108-20-235-196.bs:8333 ESTABLISHED 2171/bitcoind       
tcp        0      0 vitaly:33671                bk-in-f102.1e100.net:https  ESTABLISHED 2016/firefox        
tcp        0      0 vitaly:46155                host86-144-29-61.range:8333 ESTABLISHED 2171/bitcoind       
tcp        0      0 vitaly:45357                cpe-098-026-012-202.nc:8333 ESTABLISHED 2171/bitcoind       
tcp        0      0 *:http                      *:*                         LISTEN      1370/httpd          
tcp        0      0 vitaly:ipp                  *:*                         LISTEN      1000/cupsd  

bitcion.conf:

rpcuser=user
rpcpassword=123456

rpcport=8332

What should I check?

4

2 回答 2

1

确保允许您的服务器 ip(php 部分所在的位置!)

    rpcuser=user
    rpcpassword=123456
    rpcport=8332
    rpcallowip=192.168.0.123 (server php ip)

我每次都忘了做,每次运行php都会给我连接错误或空白。:/

于 2017-01-26T00:47:19.660 回答
0

如果您的服务器设置为通过证书而不是密码进行身份验证,请检查您是否通过 HTTPS 而不是 HTTP 进行连接。

于 2013-05-03T08:43:23.983 回答