예제 #1
0
{
    $connected = @fsockopen("alpha.wallhaven.cc", 80);
    if ($connected) {
        $is_conn = true;
        //action when connected
        fclose($connected);
    } else {
        $is_conn = false;
        //action in connection failure
    }
    return $is_conn;
}
// Clean up files/images.
array_map('unlink', glob($downloadPath . '/wallhaven-*'));
if (isConnected()) {
    $wh = new Wallhaven($account["username"], $account["password"]);
    $result = [];
    $dt = new DateTime();
    foreach ($time as $t) {
        $fromTime = new DateTime($t['from']);
        if ($dt > $fromTime) {
            $result = array_merge($default, $t);
        } else {
            break;
        }
    }
    $wallpapers = $wh->filter()->keywords($result['keywords'])->categories($result["categories"])->purity($result["purity"])->sorting($result["sorting"])->resolutions($result["resolutions"])->ratios($result["ratios"])->pages(1)->getWallpapers();
    $id = $wallpapers[0]->getId();
    $url = $wallpapers[0]->getImageUrl();
    $fileName = trim(substr($url, strrpos($url, '/') + 1));
    mkdir($downloadPath, 0700, true);
예제 #2
0
 public function testCachedIsFaster()
 {
     $wh = new Wallhaven();
     $start1 = microtime(true);
     $w1 = $wh->search("cars")[0];
     $w1->setCacheEnabled(false);
     $w1->getFavorites();
     $time1 = microtime(true) - $start1;
     echo "Cache disabled: " . round($time1 * 1000) . " ms" . PHP_EOL;
     $start2 = microtime(true);
     $w1 = $wh->search("cars")[0];
     // Cache is implicitly enabled
     $w1->getFavorites();
     $time2 = microtime(true) - $start2;
     echo "Cache enabled:  " . round($time2 * 1000) . " ms" . PHP_EOL;
     $this->assertTrue($time2 < $time1);
 }