$method, 'params' => $params, 'id' => $json_id ); $post=json_encode($json); $req ="POST / HTTP/1.1\r\n"; $req.="Authorization: Basic {$auth}\r\n"; $req.="Content-Type: application/json\r\n"; $req.='Content-Length: '.strlen($post)."\r\n"; $req.="Connection: Keep-Alive\r\n\r\n"; $req.= $post; $err=0; do { $is_ok = @fputs($fp[$fparr], $req); if($is_ok<1) ConnToCore($fparr); } while($is_ok <1); do { $line = fgets($fp[$fparr],8192); if(strpos($line,': ')>0) { $line_parts=explode(': ',$line); $headers[$line_parts[0]]=trim($line_parts[1]); } } while($line !=="\r\n" && $line!==false); if(isset($headers['Content-Length'])) $iv=(int)$headers['Content-Length']; else $iv=0; if($iv>0) { $reply=''; while($iv>0) { $buf=fread($fp[$fparr],intval($iv)); $iv -= strlen($buf); $reply.=$buf; } } else { return false; unset($headers); } if((isset($headers['Connection']) && $headers['Connection'] ==='close') || !isset($headers)) { ConnToCore($fparr); } return json_decode($reply,true); } function ConnToCore($fparr=0) { global $IP,$port,$fp; if(is_resource($fp[$fparr])) fclose($fp[$fparr]); $fp[$fparr] = stream_socket_client("tcp://{$IP}:{$port}", $err, $err2, 60,STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT); if(!is_resource($fp[$fparr])) { echo "Failed opening conn to bitcoin-qt . . .\n"; } else { while (1) { $w = array($fp[$fparr]); $r = $e = NULL; if(stream_select($r, $w, $e, 30, 0)) { unset($w,$r,$e); return; } } } } do { $startt=microtime(true); do { $result = SendJson('getconnectioncount',array(),0,$json_id1); } while(!is_null($result['error']) || $result['id']!==$json_id1); $conn=$result['result']; do { $result2 = SendJson('getblockcount',array(),0,$json_id2); } while(!is_null($result2['error']) || $result2['id']!==$json_id2); $best=$result2['result']; $endtt=microtime(true); $diff=$endtt-$startt; $time=@date("[H:i:s]"); echo "{$time} Blocks: {$best} - - - Connections: {$conn} - - - Time taken: {$diff}s\n"; Sleep(10); }while(1); ?>