It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('phpseclib/Net/SSH2.php');
header('refresh:600; url=index.php'); //change this to change the refresh in seconds (how often you want it to check on your machines)
date_default_timezone_set('America/Los_Angeles');
$machines = array
(
1 => array(
'name' => 'Mini-1',
'ip' => '192.168.1.175',
'user' => 'root',
'password' => 'root',
'threshold' => 14,
),
2 => array(
"name" => "Mini-2",
"ip" => "192.168.1.160",
'user' => 'root',
'password' => 'root',
"threshold" => 12,
),
3 => array(
"name" => "Mini-3",
"ip" => "192.168.1.51",
'user' => 'root',
'password' => 'root',
"threshold" => 12,
),
4 => array(
"name" => "Mini-4",
"ip" => "192.168.1.52",
'user' => 'root',
'password' => 'root',
"threshold" => 12,
)
);
foreach ($machines as &$machine)
{
createEmptyLogs($machine);
getstats($machine);
if(checkFails($machine)) restart($machine);
if(!file_exists( "logs/overallhashrate.csv" )) file_put_contents("logs/overallhashrate.csv", "time,total hashrate\r\n", FILE_APPEND);
}
printTotalHashrate($machines);
echo '
';
function createEmptyLogs($machine)
{
if(!file_exists( 'logs/'.$machine['name']."hashrate.csv" )) file_put_contents('logs/'.$machine['name']."hashrate.csv", "time,".$machine['name']." hashrate\r\n", FILE_APPEND);
}
function logging($machine)
{
file_put_contents('logs/'.$machine['name']."hashrate.csv", date('j M H:i:s', time()).",".$machine['ghs5s']."\r\n", FILE_APPEND);
}
function restart($machine)
{
$ssh = new Net_SSH2($machine['ip']);
if (!$ssh->login($machine['user'], $machine['password'])) {
exit('Login Failed');
}
$ssh->exec('/etc/init.d/cgminer.sh restart >/dev/null 2>&1');
}
function checkFails(&$machine)
{
if (($machine['chain_acs1'] == 'xxxx' or $machine['chain_acs2'] == 'xxxx' or $machine['chain_acs3'] == 'xxxx' or intval($machine['ghs5s']) < intval($machine['threshold'])) and intval($machine['elapsed']) > 120)
return true; //this restarts any machine with a 'failed' ASIC chain or one that has been powered on for more than 2 minutes and doesn't meet your threshold value
else return false;
}
function getstats(&$machine)
{
// create a socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, $machine['ip'], 4028);
if ($socket === false || $result === false) {
echo $machine['name']. " appears to be offline!
";
$machine['ghs5s'] = 0;
$machine['ghsav'] = 0;
$machine['chain_rate1'] = 0;
$machine['chain_rate2'] = 0;
$machine['chain_rate3'] = 0;
return;
}
else
{
// send a 'summary' command to antminer
$in = '{"command":"stats"}';
$out = '';
socket_write($socket, $in, strlen($in));
// read output from antminer
$output="";
while ($out = socket_read($socket, 2048)) {
$output=$output.$out;
}
socket_close($socket);
$output = strtolower($output);
$output = str_replace(" ", "", $output);
$output = str_replace(",", ":", $output);
$output = str_replace("\"", "", $output);
$output = str_replace("}", "", $output);
$output = str_replace("]", "", $output);
$output = explode(":", substr($output,strpos($output,"elapsed"),strpos($output,"id:1")));
foreach($output as $i => $item) //create the rest of the item entries
{
if ($i % 2 == 0)
$machine[$output[$i]] = $output[$i+1];
}
printmachinestats($machine); //Don't print stats or logs if they aren't online
logging($machine);
}
//print_r($machine);
/* old method of parsing string manually
$machine['totalhashrate']=substr($output,strpos($output,"GHS 5s")+9);
$machine['totalhashrate']=floatval(substr($machine['totalhashrate'],0, strpos($machine['totalhashrate'],"GHS av")));
$machine['uptime']=substr($output,strpos($output,"Elapsed")+9);
$machine['uptime']=floatval(substr($machine['uptime'],0, strpos($machine['uptime'],"GHS 5s")));
$machine['board1hash']=substr($output,strpos($output,"chain_rate1")+14);
$machine['board1hash']=floatval(substr($machine['board1hash'],0, strpos($machine['board1hash'],"chain_rate2")));
$machine['board2hash']=substr($output,strpos($output,"chain_rate2")+14);
$machine['board2hash']=floatval(substr($machine['board2hash'],0, strpos($machine['board2hash'],"chain_rate3")));
$machine['board3hash']=substr($output,strpos($output,"chain_rate3")+14);
$machine['board3hash']=floatval(substr($machine['board3hash'],0, strpos($machine['board3hash'],"}],")));
$machine['board1status']=substr($output,strpos($output,"chain_acs1")+13);
$machine['board1status']=substr($machine['board1status'],0, strpos($machine['board1status'],"chain_acs2")-3);
$machine['board2status']=substr($output,strpos($output,"chain_acs2")+13);
$machine['board2status']=substr($machine['board2status'],0, strpos($machine['board2status'],"chain_acs3")-3);
$machine['board3status']=substr($output,strpos($output,"chain_acs3")+13);
$machine['board3status']=substr($machine['board3status'],0, strpos($machine['board3status'],"chain_hw1")-3);
*/
}
function printmachinestats(&$machine)
{
print $machine['name'];
echo '
';
print "IP Address = ".$machine['ip'];
echo '
';
print "Hashrate = ".$machine['ghsav']. " KSol/S";
echo '
';
print "Uptime = ".secondsToTime($machine['elapsed']);
echo '
';
print "Board 1 Hash = ".$machine['chain_rate1']. " KSol/S";
echo '
';
print "Board 2 Hash = ".$machine['chain_rate2']. " KSol/S";
echo '
';
print "Board 3 Hash = ".$machine['chain_rate3']. " KSol/S";
echo '
';
print "Board 1 Status = ".$machine['chain_acs1'];
echo '
';
print "Board 2 Status = ".$machine['chain_acs2'];
echo '
';
print "Board 3 Status = ".$machine['chain_acs3'];
echo '
';
echo '
';
}
function printTotalHashrate($machines)
{
$total = 0;
foreach ($machines as &$machine)
{
$total += $machine['ghs5s'];
}
print "Total Hashrate = " . $total. " KSol/S";
//['2004', 1000, 400]
file_put_contents("logs/overallhashrate.csv", date('j M H:i:s', time()).",".$total."\r\n", FILE_APPEND); //totals Hashrate
}
function secondsToTime($seconds)
{
$dtF = new \DateTime('@0');
$dtT = new \DateTime("@$seconds");
return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
}
?>