-
Notifications
You must be signed in to change notification settings - Fork 21
/
run.php
94 lines (76 loc) · 2.23 KB
/
run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
date_default_timezone_set('America/Los_Angeles');
require_once('StratumServer.php');
require_once('Util.php');
require_once('colour.php');
$pools = array(
0 => array(
'name' => 'Whatever you want to call this connection',
'host' => 'some.stratum.com',
'port' => '3333',
'user' => 'my.user',
'pass' => 'password'
),
1 => array(
'name' => 'Whatever you want to call this connection',
'host' => 'some.stratum.com',
'port' => '3333',
'user' => 'my.user',
'pass' => 'password'
),
);
$chosen_pool = 1;
$name = $pools[$chosen_pool]['name'];
echo "Chosen pool: {$name}\n";
$server = new StratumServer();
stratumInit($chosen_pool);
while(1) {
if(!$server->connected()) {
stratumInit($chosen_pool);
continue;
}
check($server->poll(30,1,'/full/path/to/where/you/write/worker/solution/w.txt'));
}
echo "-=Finished=-\r\n";
die;
function stratumInit($chosen_pool) {
global $server, $pools;
$host = $pools[$chosen_pool]['host'];
$port = $pools[$chosen_pool]['port'];
$user = $pools[$chosen_pool]['user'];
$pass = $pools[$chosen_pool]['pass'];
if(!$server->connected()) {
check($server->connect($host, $port), true);
check($server->subscribe(), true);
check($server->poll(5));
check($server->authorize($user, $pass), true);
check($server->poll(5));
} else {
// don't want to spam trying connections
sleep(1);
}
}
/**
* Checks the results from a stdResult and echoes the..result
* @param array $result
* @param boolean $die die on a failed result?
*/
function check(array $result, $die = false) {
if(is_array($result[0])) {
foreach($result as $result_next) {
check($result_next, $die);
}
}
$date_str = date('d/m/y H:i:s')." ";
if($result[0] === false) {
echo $date_str.B_RED."FAIL: ".CLEAR.trim($result[1])."\r\n";
if($die) {
die;
}
}
if($result[0] === true && isset($result[1]) && is_string($result[1]) && strlen($result[1]) > 0) {
echo $date_str.B_GREEN."SUCCESS: ".CLEAR.trim($result[1])."\r\n";
}
}