コード例 #1
0
ファイル: fetchandparse.php プロジェクト: erorus/realmpop
function GetCharacterNames($realm)
{
    global $caughtKill, $ownerRealms;
    $result = [];
    heartbeat();
    DebugMessage("Fetching {$realm['region']} {$realm['canonical']}");
    $url = GetBattleNetURL($realm['region'], "wow/auction/data/{$realm['canonical']}");
    $json = FetchHTTP($url);
    $dta = json_decode($json, true);
    if (!isset($dta['files'])) {
        DebugMessage("{$realm['region']} {$realm['canonical']} returned no files.", E_USER_WARNING);
        return $result;
    }
    heartbeat();
    if ($caughtKill) {
        return $result;
    }
    $url = $dta['files'][0]['url'];
    $outHeaders = array();
    $json = FetchHTTP($url, [], $outHeaders);
    if (!$json) {
        heartbeat();
        if ($caughtKill) {
            return $result;
        }
        DebugMessage("No data from {$url}, waiting 5 secs");
        http_persistent_handles_clean();
        sleep(5);
        heartbeat();
        if ($caughtKill) {
            return $result;
        }
        $json = FetchHTTP($url, [], $outHeaders);
    }
    if (!$json) {
        heartbeat();
        if ($caughtKill) {
            return $result;
        }
        DebugMessage("No data from {$url}, waiting 15 secs");
        http_persistent_handles_clean();
        sleep(15);
        heartbeat();
        if ($caughtKill) {
            return $result;
        }
        $json = FetchHTTP($url, [], $outHeaders);
    }
    if (!$json) {
        DebugMessage("No data from {$url}, giving up");
        return $result;
    }
    $xferBytes = isset($outHeaders['X-Original-Content-Length']) ? $outHeaders['X-Original-Content-Length'] : strlen($json);
    DebugMessage("{$realm['region']} {$realm['canonical']} data file " . strlen($json) . " bytes" . ($xferBytes != strlen($json) ? ' (transfer length ' . $xferBytes . ', ' . round($xferBytes / strlen($json) * 100, 1) . '%)' : ''));
    heartbeat();
    if ($caughtKill) {
        return $result;
    }
    $c = preg_match_all('/"owner":"([^"\\?]+)","ownerRealm":"([^"\\?]+)"/', $json, $res);
    for ($x = 0; $x < $c; $x++) {
        $seller = $res[1][$x];
        $sellerRealm = $res[2][$x];
        if (!isset($ownerRealms[$sellerRealm])) {
            continue;
        }
        $result[$sellerRealm][$seller] = 0;
    }
    heartbeat();
    return $result;
}
コード例 #2
0
ファイル: realms2houses.php プロジェクト: erorus/realmpop
function GetDataRealms($region, $hash)
{
    heartbeat();
    $region = strtolower($region);
    $pth = __DIR__ . '/realms2houses_cache';
    if (!is_dir($pth)) {
        DebugMessage('Could not find realms2houses_cache!', E_USER_ERROR);
    }
    $cachePath = "{$pth}/{$region}-{$hash}.json";
    if (file_exists($cachePath) && filemtime($cachePath) > time() - 23 * 60 * 60) {
        return json_decode(file_get_contents($cachePath), true);
    }
    $result = array('slug' => false, 'realms' => array());
    $url = sprintf('http://%s.battle.net/auction-data/%s/auctions.json', $region, $hash);
    $outHeaders = array();
    $json = FetchHTTP($url, [], $outHeaders);
    if (!$json) {
        DebugMessage("No data from {$url}, waiting 5 secs");
        http_persistent_handles_clean();
        sleep(5);
        $json = FetchHTTP($url, [], $outHeaders);
    }
    if (!$json) {
        DebugMessage("No data from {$url}, waiting 15 secs");
        http_persistent_handles_clean();
        sleep(15);
        $json = FetchHTTP($url, [], $outHeaders);
    }
    if (!$json) {
        if (file_exists($cachePath) && filemtime($cachePath) > time() - 3 * 24 * 60 * 60) {
            DebugMessage("No data from {$url}, using cache");
            return json_decode(file_get_contents($cachePath), true);
        }
        DebugMessage("No data from {$url}, giving up");
        return $result;
    }
    $xferBytes = isset($outHeaders['X-Original-Content-Length']) ? $outHeaders['X-Original-Content-Length'] : strlen($json);
    DebugMessage("{$region} {$hash} data file " . strlen($json) . " bytes" . ($xferBytes != strlen($json) ? ' (transfer length ' . $xferBytes . ', ' . round($xferBytes / strlen($json) * 100, 1) . '%)' : ''));
    if (preg_match('/"slug":"([^"?]+)"/', $json, $m)) {
        $result['slug'] = $m[1];
    }
    preg_match_all('/"ownerRealm":"([^"?]+)"/', $json, $m);
    $result['realms'] = array_values(array_unique($m[1]));
    file_put_contents($cachePath, json_encode($result));
    return $result;
}
コード例 #3
0
/**
 * Test Http functions.
 */
function test_functions()
{
    http_cache_last_modified();
    http_chunked_decode();
    http_deflate();
    http_inflate();
    http_build_cookie();
    http_date();
    http_get_request_body_stream();
    http_get_request_body();
    http_get_request_headers();
    http_match_etag();
    http_match_modified();
    http_match_request_header();
    http_support();
    http_negotiate_charset();
    http_negotiate_content_type();
    http_negotiate_language();
    ob_deflatehandler();
    ob_etaghandler();
    ob_inflatehandler();
    http_parse_cookie();
    http_parse_headers();
    http_parse_message();
    http_parse_params();
    http_persistent_handles_clean();
    http_persistent_handles_count();
    http_persistent_handles_ident();
    http_get();
    http_head();
    http_post_data();
    http_post_fields();
    http_put_data();
    http_put_file();
    http_put_stream();
    http_request_body_encode();
    http_request_method_exists();
    http_request_method_name();
    http_request_method_register();
    http_request_method_unregister();
    http_request();
    http_redirect();
    http_send_content_disposition();
    http_send_content_type();
    http_send_data();
    http_send_file();
    http_send_last_modified();
    http_send_status();
    http_send_stream();
    http_throttle();
    http_build_str();
    http_build_url();
}