miner.php add a socket RCV timeout for if cgminer is hung and the API thread is still running
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
diff --git a/miner.php b/miner.php
index 6f750be..be420aa 100644
--- a/miner.php
+++ b/miner.php
@@ -1,7 +1,8 @@
<?php
session_start();
#
-global $miner, $port, $readonly, $notify, $rigs, $socktimeoutsec;
+global $miner, $port, $readonly, $notify, $rigs;
+global $socksndtimeoutsec, $sockrcvtimeoutsec;
global $checklastshare, $hidefields;
global $ignorerefresh, $changerefresh, $autorefresh;
global $allowcustompages, $customsummarypages;
@@ -38,12 +39,16 @@ $checklastshare = true;
# e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028:Sugoi');
$rigs = array('127.0.0.1:4028');
#
-# This should be OK for most cases
-# 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
+# These should be OK for most cases
+# However, the longer SND is, the longer you have to wait while
+# php hangs if the target cgminer isn't runnning or listening
+# RCV should only ever be relevant if cgminer has hung but the
+# API thread is still running, RCV would normally be >= SND
+# Feel free to increase SND if your network is very slow
+# or decrease RCV if that happens often to you
# Also, on some windows PHP, apparently the $usec is ignored
-$socktimeoutsec = 10;
+$socksndtimeoutsec = 10;
+$sockrcvtimeoutsec = 40;
#
# List of fields NOT to be displayed
# You can use this to hide data you don't want to see or don't want
@@ -260,7 +265,7 @@ $error = null;
#
function getsock($addr, $port)
{
- global $haderror, $error, $socktimeoutsec;
+ global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
$error = null;
$socket = null;
@@ -277,7 +282,8 @@ function getsock($addr, $port)
// 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));
+ socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $socksndtimeoutsec, 'usec' => 0));
+ socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $sockrcvtimeoutsec, 'usec' => 0));
$res = socket_connect($socket, $addr, $port);
if ($res === false)