Author

Topic: [solved] http error from json-rpc in php (Read 4791 times)

legendary
Activity: 980
Merit: 1003
I'm not just any shaman, I'm a Sha256man
March 06, 2013, 03:07:32 AM
#7
Perhaps my PHP BDK library might help http://bitcoindevkit.com
newbie
Activity: 17
Merit: 0
March 06, 2013, 03:06:28 AM
#6
Try setting stream_context timeout to longer time, might help.

Or try cURL!

And try taking the http:// outta there.

And if it helps, here's an example on how to do it:
http://pastebin.com/YCYb0nPv

Let me know if any of these works.

curl solved all of my problems!  got the code I needed here: http://pastebin.com/vREuHVr5
where would you like the 5 btc sent?
legendary
Activity: 1498
Merit: 1000
March 05, 2013, 11:13:56 PM
#5
Your getting that error cause your script can't talk to your bitcoind, make sure you use the allowip, make sure you have the server=1, and rpcuser and rpcpass commands in your config file.
full member
Activity: 141
Merit: 100
March 05, 2013, 11:10:31 PM
#4
I'm not sure about the second error but your first is caused when bitcoin returns an error. json-rpc can't handle errors and will throw an exception which would stop your entire script. When you try to send coins if there are insufficent funds bitcoin will return an error which will cause json to throw an exception. In this case you should include checks:
Quote
$balance = $bitcoind->getbalance();
$fee = 0.0005;

if($balance - $fee >= .00000001)
                   $bitcoind->sendto();
else echo "Insufficient Funds";
newbie
Activity: 17
Merit: 0
March 05, 2013, 07:16:55 PM
#3
Try setting stream_context timeout to longer time, might help.

Or try cURL!

And try taking the http:// outta there.

And if it helps, here's an example on how to do it:
http://pastebin.com/YCYb0nPv

Let me know if any of these works.

Great ideas.  I'll play around with this and get back to you.
legendary
Activity: 1511
Merit: 1072
quack
March 05, 2013, 05:08:26 PM
#2
Try setting stream_context timeout to longer time, might help.

Or try cURL!

And try taking the http:// outta there.

And if it helps, here's an example on how to do it:
http://pastebin.com/YCYb0nPv

Let me know if any of these works.
newbie
Activity: 17
Merit: 0
March 05, 2013, 04:56:25 PM
#1
I am using the json-rpc php library from the bitcoin wiki (http://jsonrpcphp.org/) to send commands to my bitcoind instance.  For the most part, it works as expected, but occasionally, when I use the sendtoaddress command, it will return one of the following errors:
Code:
fopen(http://...@localhost:8334/): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
or
Code:
fopen(http://...@localhost:8334/): failed to open stream: HTTP request failed!
I noticed that the first one seems to happen only when there are insufficient funds in the wallet.  The second seems to happen at random.  When the first occurs, no coins are sent.  When the second occurs, the coins are almost always sent just as if there was no error even though it seems, based on the error, that the command never made it to bitcoind.  Occasionally though, the second error will be returned and the coins aren't sent.

This ambiguity is a problem for me.  What I would really like is for the jsonrpc client to return a meaningful error when it cannot process the request (such as insufficient funds) and to return the usual output (txid) when sendtoaddress is successfully executed.  I'm most comfortable in php, but am willing to learn other languages to achieve the same ends.  Ultimately I need to take addresses/amounts from a mysql database and construct transactions in my bitcoind server.

So, if anyone knows how to make this work in php or another language, perhaps perl or ruby or python and can walk me though it, and it works as described, 5 btc will be yours.
Jump to: