Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Bungeebones on April 08, 2014, 01:12:33 AM



Title: PHP Only Partially Reading Bitcoind
Post by: Bungeebones on April 08, 2014, 01:12:33 AM
I've got two different PHP scripts (listed below) accessing Bitcoind via jsonRPC and neither one is working properly. And the command line reports are acting weird too.

I have both Bitcoind and Bitcoin-QT installed. I made a spend to one of its wallets and at Blockchain it reported 37 confirmations. I got the transaction id from the cl using bitcoind listtransactions but it reported NO confirmations there. Then, when I repeated the command a couple minutes later from the cl there was no longer any mention of the transaction.

The two php scripts never have shown the transaction at all.

One simple script -
 
Code:
require_once 'jsonRPCClient.php';
 
  $bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/');
 
  echo "<pre>\n";
  print_r($bitcoin->getinfo()); echo "\n";
  echo "Received: ".$bitcoin->getreceivedbylabel("Your Address")."\n";
  echo "</pre>";

While the second is a more elaborate class from http://www.phpclasses.org/package/6739-PHP-Manage-Bitcoin-virtual-currency-accounts.html (http://www.phpclasses.org/package/6739-PHP-Manage-Bitcoin-virtual-currency-accounts.html). I've tried from both the test_bitcoin.php page and the test_bitcoin_rpc.php page. Apart from not reporting the proper balance everything appears ok in them.

So, in summary, the php pages don't report the proper balance (the script doesn't report confirmations) and the command line reports the proper balance but not the correct confirmations and then disappears altogether.  

Any help will be greatly appreciated.


Title: Re: PHP Only Partially Reading Bitcoind
Post by: gwlloyd on April 08, 2014, 02:55:32 PM
Is the blockchain on bitcoind up-to-date? i.e. on getinfo does it show the same number of blocks as blockchain.info .. a confirm is a block so if it hasn't caught up to all blocks then it wont show the confirms.


Title: Re: PHP Only Partially Reading Bitcoind
Post by: Bungeebones on April 08, 2014, 03:40:59 PM
Hi,

Thanks for the reply and the help.

I haven't quite figured out what is all available from the command line. I can't tell when it has completed updating after I start bitcoind from the command line so what I do is I'll start the Bitcoin client from the GUI and let it update the blockchain. So I would guess that the blockchain is up to date because I updated for sure with the GUI client, then I shut it down and started bitcoind from the cl. Also I noticed that when I open the Bitcoin QT GUI it reports it is "rescanning". That seems odd to me. Is that an indication something is wrong and the two aren't compatible?

Also, it did see the transaction at the cl once, then the report disappeared. I also tried every command to find it recorded as a balance and it only reported a zero balance. It is only a small token test amount so that loss is not important. I'm trying to figure it all out and what I am doing wrong.

Here is what I have found out so far ...

At the CL I found I have two wallets in the account. The account's name is "TEST" and I didn't create it that I know of. I would assume it is somewhere created in that script or does bitcoind create TEST at install?

Of those two wallets I know I created one of them with the Gui client. That is the one I sent the transaction to and the GUI is reporting the correct balance.

So either I am misunderstanding the relationship between bitcoind and bitcoin qt (I thought they use the same accounts, wallets etc) or something is wrong with the scripts. Another possibility is that I'm entering the wrong commands on the CL but I've tried everything, I believe, and am using commands from what I think are reliable and up to date sources.


EDIT: I just had severe problem loading QT. It crashed 3 times without being able to load the wallet. I renamed the wallet.bak file and it is now loaded and updating. Am I messing it up going back and forth between QT and the Bitcoind CL?





Title: Re: PHP Only Partially Reading Bitcoind
Post by: fbueller on April 09, 2014, 01:49:39 AM
It was probably still reindexing when you ran this. You can check the progress of the reindex by doing bitcoind getinfo and checking the current height.


Title: Re: PHP Only Partially Reading Bitcoind
Post by: gweedo on April 09, 2014, 01:52:57 AM
Code:
tail -f ~/.bitcoin/debug.log

That is going to be your friend in SSH. It will tell you what block and the progress of completion.


Title: Re: PHP Only Partially Reading Bitcoind
Post by: DeathAndTaxes on April 09, 2014, 02:06:50 AM
As a general rule before you start messing around with custom applications just try executing the command from the command line
bitcoind <command> <arguments>
if you get nothing there then it isn't a PHP issue it means the bitcoind is broken or behind.

bitcoind getinfo

should give you some basic info like connections to the network and blockheight.


Title: Re: PHP Only Partially Reading Bitcoind
Post by: someguy123 on April 09, 2014, 11:03:05 PM
As a general rule before you start messing around with custom applications just try executing the command from the command line
bitcoind <command> <arguments>
if you get nothing there then it isn't a PHP issue it means the bitcoind is broken or behind.

bitcoind getinfo

should give you some basic info like connections to the network and blockheight.
This ^^

Bitcoin and other coin daemons are VERY SLOW and can return odd results when they're behind on blocks. If you notice long load-times, that's one of the reasons most likely.


Title: Re: PHP Only Partially Reading Bitcoind
Post by: Bungeebones on April 09, 2014, 11:58:23 PM
Thanks everyone. It was all helpful and am getting to understand it a little better now. Yes, the issue was that the blockchain hadn't finished loading yet. The next morning the transaction and balance were correct.

Gosh the documentation is sporadic. Maybe I'll attempt writing a how-to when I'm done (I've gotten enough practice :-)