Hey, so implementing FaucetHUB over here,
first of all, could you please merge this patch?
--- faucethub-orig.php 2016-11-25 09:21:04.000000000 +0400
+++ faucethub.php 2016-11-25 13:40:06.742170900 +0400
@@ -18,15 +18,26 @@
{
protected $api_key;
protected $currency;
+ protected $timeout;
public $last_status = null;
protected $api_base = "https://faucethub.io/api/v1/";
- public function __construct($api_key, $currency = "BTC", $disable_curl = false, $verify_peer = true) {
+ public function __construct($api_key, $currency = "BTC", $disable_curl = false, $verify_peer = true, $timeout = null) {
$this->api_key = $api_key;
$this->currency = $currency;
$this->disable_curl = $disable_curl;
$this->verify_peer = $verify_peer;
$this->curl_warning = false;
+ $this->setTimeout($timeout);
+ }
+
+ public function setTimeout($timeout) {
+ if($timeout === null) {
+ $socket_timeout = ini_get('default_socket_timeout');
+ $script_timeout = ini_get('max_execution_time');
+ $timeout = min($script_timeout / 2, $socket_timeout);
+ }
+ $this->timeout = $timeout;
}
public function __execPHP($method, $params = array()) {
@@ -35,7 +46,8 @@
"http" => array(
"method" => "POST",
"header" => "Content-type: application/x-www-form-urlencoded\r\n",
- "content" => http_build_query($params)
+ "content" => http_build_query($params),
+ "timeout" => $this->timeout,
),
"ssl" => array(
"verify_peer" => $this->verify_peer
@@ -43,6 +55,12 @@
);
$ctx = stream_context_create($opts);
$fp = fopen($this->api_base . $method, 'rb', null, $ctx);
+ if (!$fp) {
+ return array(
+ 'status' => 503,
+ 'message' => 'Connection error',
+ );
+ }
$response = stream_get_contents($fp);
if($response && !$this->disable_curl) {
$this->curl_warning = true;
@@ -58,11 +76,18 @@
} else {
$response = $this->__execCURL($method, $params);
}
- $response = json_decode($response, true);
+ if(is_array($response)) { //connection error
+ return $response;
+ }
+ $response = @json_decode($response, true);
if($response) {
$this->last_status = $response['status'];
} else {
$this->last_status = null;
+ $response = array(
+ 'status' => 502,
+ 'message' => 'Invalid response',
+ );
}
return $response;
}
@@ -75,10 +100,14 @@
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_peer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_TIMEOUT, (int)$this->timeout);
$response = curl_exec($ch);
if(!$response) {
- $response = $this->__execPHP($method, $params);
+ return array(
+ 'status' => 504,
+ 'message' => 'Connection error',
+ );
}
curl_close($ch);
@@ -86,6 +115,8 @@
}
public function send($to, $amount, $referral = "false", $ip_address = "") {
+ if ($referral === false) $referral = 'false';
+ if ($referral === true) $referral = 'true';
$r = $this->__exec("send", array("to" => $to, "amount" => $amount, "referral" => $referral, "ip_address" => $ip_address));
if (array_key_exists("status", $r) && $r["status"] == 200) {
return array(
here's the super-long explanation of what it does
https://bitcointalksearch.org/topic/m.13080814TL;DR version is that it
adds timeout checks -- good
adds proper handling of connection errors and wrong responses -- good
does that by adding fake error codes -- bad, please review
does this thing
$response = curl_exec($ch);
if(!$response) {
- $response = $this->__execPHP($method, $params);
-- because if it failed, it failed, magical silent retry with another method is evil -- controversial
etc
Feel free to ignore the code, but please do tend to the problems it solves. And of course, ask me anything if it needs any clarifications.
Next up, I've signed up with AddressA. Now I'm trying to withdraw to AddressB, and FH suggests I link it to my account on address check page.
(Honestly, this whole "signup before use" is not something I like at all, but I'll post at another thread to keep this one clean)
But, anyways, as I try to link the address, by clicking the buton, I just get redirected to my dashboard... And it looks like there is no option to link currently? I see my original AddressA there, with no ability to change it. Game over?
And the most important question of all: where do I get 'em sweet fake coins?