miner.php add a timeout so you don't sit and wait ... forever
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 95 96 97 98 99 100
diff --git a/miner.php b/miner.php
index 5d8c55f..e3a816d 100644
--- a/miner.php
+++ b/miner.php
@@ -1,7 +1,7 @@
<?php
session_start();
#
-global $miner, $port, $readonly, $notify, $rigs;
+global $miner, $port, $readonly, $notify, $rigs, $socktimeoutsec;
#
# Don't touch these 2 - see $rigs below
$miner = null;
@@ -25,6 +25,15 @@ $notify = true;
# e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028');
$rigs = array('127.0.0.1:4028');
#
+# This should be OK for most cases
+# If you really do have a slow netowrk connection from php to cgminer
+# then 2 may not be enough
+# However, the longer it is the longer you have to wait while php
+# hangs if the target cgminer isn't runnning or listening
+# Feel free to increase it if your network is very slow
+# Also, on some windows PHP, apparently the $usec is ignored
+$socktimeoutsec = 2;
+#
$here = $_SERVER['PHP_SELF'];
#
global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
@@ -39,6 +48,10 @@ $dfmt = 'H:i:s j-M-Y \U\T\CP';
global $showndate;
$showndate = false;
#
+# For summary page to stop retrying failed rigs
+global $rigerror;
+$rigerror = array();
+#
function htmlhead($checkapi)
{
global $error, $readonly, $here;
@@ -85,7 +98,7 @@ $error = null;
#
function getsock($addr, $port)
{
- global $error;
+ global $error, $socktimeoutsec;
$socket = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@@ -97,6 +110,11 @@ function getsock($addr, $port)
return null;
}
+ // Ignore if this fails since the socket connect may work anyway
+ // and nothing is gained by aborting if the option cannot be set
+ // since we don't know in advance if it can connect
+ socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socktimeoutsec, 'usec' => 0));
+
$res = socket_connect($socket, $addr, $port);
if ($res === false)
{
@@ -569,13 +587,18 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
global $miner, $port;
global $error, $readonly, $notify, $rigs;
global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
+ global $rigerror;
$header = $head;
$anss = array();
$count = 0;
+ $preverr = count($rigerror);
foreach ($rigs as $rig)
{
+ if (isset($rigerror[$rig]))
+ continue;
+
$parts = explode(':', $rig, 2);
if (count($parts) == 2)
{
@@ -588,6 +611,7 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
{
echo "<tr><td colspan=100>Error on rig $count getting $des: ";
echo $warnfont.$error.$warnoff.'</td></tr>';
+ $rigerror[$rig] = $error;
$error = null;
}
else
@@ -598,7 +622,10 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
if (count($anss) == 0)
{
- echo "<tr><td>Failed to access any rigs successfully</td></tr>";
+ echo '<tr><td>Failed to access any rigs successfully';
+ if ($preverr > 0)
+ echo ' (or rigs had previous errors)';
+ echo '</td></tr>';
return;
}