Title: JSON RPC for Bitcoin intermittently sending bad responses? Post by: joe on October 09, 2010, 10:44:40 AM I am using the PHP jsonRPCClient to connect to my bitcoin 0.3.11beta client, which I am running on Windows with bitcoin -server. I use calls such as getreceivedbyaddress, and occasionally sendtoaddress. I am noticing the following error occur intermittently:
PHP Warning: fopen(http://...@127.0.0.1:.../): failed to open stream: HTTP request failed! To overcome this in the PHP code, I simply placed all json calls inside of try statements, then inside while loops that kept trying until there was no exception. The behavior appeared to be 50/50 success/fail, so half the time it only took 1 loop, 1/4 of the time it took 2 loops, etcetera. In any case, the while loops allowed me to pull the result out of the call that I needed. The problem was reduced significantly after an upgrade to the latest version, but it still happened maybe once out of 10 or 15 times. More recently, the problem occurred for the first time on a sendtoaddress call: fopen threw the exception, so my code tried again, and got a success. The result was a double-spend. The bitcoin server obviously processed the first one that gave me an exception. I did some research and it looks like PHP's fopen call will return an exception if it doesn't like the HTTP that comes back to it. In short, there is an incompatibility with PHP's fopen and the bitcoin client (JSON server), and I suspect this is a bitcoin issue because I have not found any reports of similar intermittent problems out of PHP's fopen function. The important part of this bug is it is completely intermittent, at least with the getreceivedbyaddress and sendtoaddress functions. With all other factors held constant, simply resubmitting the JSON request makes PHP happy, even though the server processed the first request and PHP did not like the response. Title: Re: JSON RPC for Bitcoin intermittently sending bad responses? Post by: Gavin Andresen on October 09, 2010, 07:31:40 PM The only think I can think of is that the php fopen() call is timing out. Are you trying to generate coins? Does it get better if you stop generating?
Are you using PHP5 ? If you are, try creating a stream_context with a longer timeout (see http://www.php.net/manual/en/context.http.php ). Title: Re: JSON RPC for Bitcoin intermittently sending bad responses? Post by: joe on October 09, 2010, 11:22:50 PM The only think I can think of is that the php fopen() call is timing out. Are you trying to generate coins? Does it get better if you stop generating? Are you using PHP5 ? If you are, try creating a stream_context with a longer timeout (see http://www.php.net/manual/en/context.http.php ). No, it is not timing out. The fopen call quickly throws the exception. In my php error log, if an exception happens several times in a row the time for all exceptions are within a second or two. And the site does not hang when these failures happen. The default timeout, as configured in my default_socket_timeout, is 60 seconds, which is certainly not being reached. No, I am not generating coins. I have always had coin generation turned off throughout the history of this problem. Yes, I am using PHP5. The timeout is not set so it should be using the default 60 seconds. Let me know if I should try entering something for timeout any way. Title: Re: JSON RPC for Bitcoin intermittently sending bad responses? Post by: lulzplzkthx on April 17, 2011, 05:21:11 PM I had this same issue, and I decided to switch over from fopen() to cURL. If your server supports it, feel free to use this library instead (the only difference is that it uses cURL. Using it is the same as always, and you shouldn't have intermittent bad requests.) Hope this helps someone.
Code: <?php Title: Re: JSON RPC for Bitcoin intermittently sending bad responses? Post by: Luke-Jr on April 18, 2011, 02:30:43 AM What timezone and locale is your bitcoind running in?
Title: Re: JSON RPC for Bitcoin intermittently sending bad responses? Post by: Coinbuck @ BTCLot on June 25, 2011, 02:20:21 AM What timezone and locale is your bitcoind running in? I'm running it on GMT in localhost and I'm having the same damn issue ! http://forum.bitcoin.org/index.php?topic=548.0 I've reported here aswell. |