-
Notifications
You must be signed in to change notification settings - Fork 56
/
hashrate-json.php
52 lines (36 loc) · 1.37 KB
/
hashrate-json.php
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
<?php
require_once 'includes.php';
require_once 'hashrate.php';
if (!isset($_SERVER['PATH_INFO']))
{
print json_encode(array("error" => "No username specified in URL path Please try again."));
exit;
}
$link = pg_pconnect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost");
if (pg_connection_status($link) != PGSQL_CONNECTION_OK)
{
pg_close($link);
$link = pg_pconnect("dbname=$psqldb user=$psqluser password='$psqlpass' host=$psqlhost");
if (pg_connection_status($link) != PGSQL_CONNECTION_OK)
{
print json_encode(array("error" => "Unable to establish a connection to the stats database. Please try again later. If this issue persists, please report it to the pool operator."));
exit;
}
}
$givenuser = substr($_SERVER['PATH_INFO'],1,strlen($_SERVER['PATH_INFO'])-1);
$user_id = get_user_id_from_address($link, $givenuser);
if (!$user_id)
{
print json_encode(array("error" => "Username $givenuser not found in database. Please try again later. If this issue persists, please report it to the pool operator."));
exit;
}
$cache_key = hash("sha256", "hashrate-json.php hashrate JSON for $givenuser with id $user_id");
$json = get_stats_cache($link, 11, $cache_key);
if ($json == "")
{
$hashrate_info = get_hashrate_stats($link, $givenuser, $user_id);
$json = json_encode($hashrate_info);
set_stats_cache($link, 11, $cache_key, $json, 30);
}
print $json;
?>