diff --git a/api/index.php b/api/index.php index 12c3a9e..4d371d0 100644 --- a/api/index.php +++ b/api/index.php @@ -7,8 +7,8 @@ $configs = array( //'EPSYTOUR'=>'epsytour.php', /* copy local.php file and edit target IP:PORT */ ); -// 5 seconds max. -set_time_limit(5); +// 3 seconds max. +set_time_limit(3); error_reporting(0); function getdataFromPears() @@ -26,7 +26,7 @@ function getdataFromPears() function ignoreField($key) { - $ignored = array('API','VER','GPU','CARD'); + $ignored = array('API','VER','GPU','CARD','GPUS','CPU'); return in_array($key, $ignored); } @@ -38,6 +38,7 @@ function translateField($key) $intl['ALGO'] = 'Algorithm'; $intl['GPUS'] = 'GPUs'; + $intl['CPUS'] = 'Threads'; $intl['KHS'] = 'Hash rate (kH/s)'; $intl['ACC'] = 'Accepted shares'; $intl['ACCMN'] = 'Accepted / mn'; @@ -63,11 +64,19 @@ function translateValue($key,$val,$data=array()) case 'UPTIME': $min = floor(intval($val) / 60); $sec = intval($val) % 60; - $val = "${min}mn ${sec}s"; + $val = "${min}mn${sec}s"; + if ($min > 180) { + $hrs = floor($min / 60); + $min = $min % 60; + $val = "${hrs}h${min}mn"; + } break; case 'NAME': $val = $data['NAME'].' '.$data['VER']; break; + case 'FREQ': + $val = sprintf("%d MHz", round(floatval($val)/1000.0)); + break; case 'TS': $val = strftime("%H:%M:%S", (int) $val); break; @@ -83,14 +92,14 @@ function displayData($data) $htm .= ''."\n"; $htm .= '\n"; if (!empty($stats)) { - $summary = $stats['summary']; + $summary = (array) $stats['summary']; foreach ($summary as $key=>$val) { if (!empty($val) && !ignoreField($key)) $htm .= ''. '\n"; } if (isset($summary['KHS'])) - $totals[$summary['ALGO']] += floatval($summary['KHS']); + @ $totals[$summary['ALGO']] += floatval($summary['KHS']); foreach ($stats['threads'] as $g=>$gpu) { $card = isset($gpu['CARD']) ? $gpu['CARD'] : ''; $htm .= '\n"; @@ -117,6 +126,7 @@ function displayData($data) $data = getdataFromPears(); ?> + ccminer rig api sample @@ -164,10 +174,10 @@ th.gpu { color: white; padding: 3px 3px; font: bolder; text-align: left; backgro td.key { width: 99px; max-width: 180px; } td.val { width: 40px; max-width: 100px; color: white; } -div.totals { margin: 16px; } +div.totals { margin: 16px; padding-bottom: 16px; } div.totals h2 { color: darkcyan; font-size: 16px; margin-bottom: 4px; } div.totals li { list-style-type: none; font-size: 16px; margin-left: 4px; margin-bottom: 8px; } -li span.algo { display: inline-block; width: 50px; max-width: 120px; } +li span.algo { display: inline-block; width: 100px; max-width: 180px; } diff --git a/api/local-sample.php b/api/local-sample.php index f81e691..3d3b2e8 100644 --- a/api/local-sample.php +++ b/api/local-sample.php @@ -5,9 +5,8 @@ defined('API_HOST') || define('API_HOST', '127.0.0.1'); defined('API_PORT') || define('API_PORT', 4068); -// 3 seconds max. -set_time_limit(3); -error_reporting(0); +// 2 seconds max. +set_time_limit(2); function getsock($port) { @@ -20,14 +19,28 @@ function getsock($port) return NULL; } + socket_set_nonblock($socket); + $res = socket_connect($socket, API_HOST, $port); - if ($res === false) { - $error = socket_strerror(socket_last_error()); + $timeout = 50; + while ($res === false && $timeout > 0) { + $err = socket_last_error($socket); + echo "."; + if ($timeout > 1 && ($err == 115 || $err == 114)) { + $timeout--; + usleep(50); + $res = socket_connect($socket, API_HOST, $port); + continue; + } + $error = socket_strerror($err); $msg = "socket connect($port) failed"; echo "ERR: $msg '$error'\n"; socket_close($socket); return NULL; } + + socket_set_block($socket); + return $socket; } @@ -110,12 +123,14 @@ function request($cmd) ob_start(); +error_reporting(0); + $summary = request('summary'); $threads = request('threads'); -$histo = array();//request('histo'); /* only enable it if required... */ +$histo = request('histo'); -ob_end_clean(); -//echo ob_get_clean()."\n"; /* allow to print protocol debug message */ +ob_end_clean(); /* swap to debug */ +//echo ob_get_clean()."\n"; header("Content-Type: application/json"); echo json_encode(compact('summary', 'threads', 'histo'))."\n";
'.$name."
'.translateField($key).''.translateValue($key, $val, $summary)."
'.$g." $card