mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-09 14:28:12 +00:00
miner.php add a timeout so you don't sit and wait ... forever
This commit is contained in:
parent
849ba896af
commit
e9d5244d44
33
miner.php
33
miner.php
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
#
|
#
|
||||||
global $miner, $port, $readonly, $notify, $rigs;
|
global $miner, $port, $readonly, $notify, $rigs, $socktimeoutsec;
|
||||||
#
|
#
|
||||||
# Don't touch these 2 - see $rigs below
|
# Don't touch these 2 - see $rigs below
|
||||||
$miner = null;
|
$miner = null;
|
||||||
@ -25,6 +25,15 @@ $notify = true;
|
|||||||
# e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028');
|
# e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028');
|
||||||
$rigs = array('127.0.0.1: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'];
|
$here = $_SERVER['PHP_SELF'];
|
||||||
#
|
#
|
||||||
global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
|
global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
|
||||||
@ -39,6 +48,10 @@ $dfmt = 'H:i:s j-M-Y \U\T\CP';
|
|||||||
global $showndate;
|
global $showndate;
|
||||||
$showndate = false;
|
$showndate = false;
|
||||||
#
|
#
|
||||||
|
# For summary page to stop retrying failed rigs
|
||||||
|
global $rigerror;
|
||||||
|
$rigerror = array();
|
||||||
|
#
|
||||||
function htmlhead($checkapi)
|
function htmlhead($checkapi)
|
||||||
{
|
{
|
||||||
global $error, $readonly, $here;
|
global $error, $readonly, $here;
|
||||||
@ -85,7 +98,7 @@ $error = null;
|
|||||||
#
|
#
|
||||||
function getsock($addr, $port)
|
function getsock($addr, $port)
|
||||||
{
|
{
|
||||||
global $error;
|
global $error, $socktimeoutsec;
|
||||||
|
|
||||||
$socket = null;
|
$socket = null;
|
||||||
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
@ -97,6 +110,11 @@ function getsock($addr, $port)
|
|||||||
return null;
|
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);
|
$res = socket_connect($socket, $addr, $port);
|
||||||
if ($res === false)
|
if ($res === false)
|
||||||
{
|
{
|
||||||
@ -569,13 +587,18 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
|
|||||||
global $miner, $port;
|
global $miner, $port;
|
||||||
global $error, $readonly, $notify, $rigs;
|
global $error, $readonly, $notify, $rigs;
|
||||||
global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
|
global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
|
||||||
|
global $rigerror;
|
||||||
|
|
||||||
$header = $head;
|
$header = $head;
|
||||||
$anss = array();
|
$anss = array();
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
$preverr = count($rigerror);
|
||||||
foreach ($rigs as $rig)
|
foreach ($rigs as $rig)
|
||||||
{
|
{
|
||||||
|
if (isset($rigerror[$rig]))
|
||||||
|
continue;
|
||||||
|
|
||||||
$parts = explode(':', $rig, 2);
|
$parts = explode(':', $rig, 2);
|
||||||
if (count($parts) == 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 "<tr><td colspan=100>Error on rig $count getting $des: ";
|
||||||
echo $warnfont.$error.$warnoff.'</td></tr>';
|
echo $warnfont.$error.$warnoff.'</td></tr>';
|
||||||
|
$rigerror[$rig] = $error;
|
||||||
$error = null;
|
$error = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -598,7 +622,10 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
|
|||||||
|
|
||||||
if (count($anss) == 0)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user