2017 © Pedro Peláez
 

library downloader

Downloader Library

image

vasily-kartashov/downloader

Downloader Library

  • Friday, June 29, 2018
  • by vasily-kartashov
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,164 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 22 % Grown

The README.md

PHP Downloader Library

CI Status Packagist Packagist Coverage Status Psalm coverage, (*1)

Example

<?php

$redisClient = new Redis();
$redisClient->connect('localhost', 6379);
$redisCachePool = new RedisCachePool($redisClient);

$downloader = Downloader($redisCachePool);

$task = Task::builder()
    ->batch(12)
    ->retry(3)
    ->validate(function ($response) {
        return strlen($response) > 1024;
    })
    ->cache('pages.', 12 * 3600)
    ->options([
        CURLOPT_SSL_VERIFYHOST => false
    ])
    ->throttle(120)
    ->add(1, 'http://example/page/1')
    ->add(2, 'http://example/page/2')
    ...
    ->add(9, 'http://example/page/9')
    ->build();

This will - send multi curl requests to the specified URLs, 12 in each batch. - The successful responses will be kept in cache for 12 hours. - The downloader will try to download each page 3 times before moving to the next batch. - If last failure was less than 2 minutes, a new download will not be attempted. - Only responses longer than 1024 are treated as successful, (*2)

$results = $downloader->execute($task);
foreach ($results as $result) {
    if ($result->successful()) {
        echo $result->content();
    } elseif ($result->failed()) {
        echo 'Failed to fetch';
    } elseif ($result->skipped()) {
        echo 'Skipping result, to avoid too many retries';
    }
}

ToDo

  • Embed Guzzle and use standards, keep this as a lean interface only
  • Add more tests

The Versions

29/06 2018

dev-master

9999999-dev

Downloader Library

  Sources   Download

The Requires

 

The Development Requires

by Vasily Kartashov

downloader

02/11 2017

0.0.4

0.0.4.0

Downloader Library

  Sources   Download

The Requires

 

The Development Requires

by Vasily Kartashov

downloader

31/10 2017

0.0.3

0.0.3.0

Downloader Library

  Sources   Download

The Requires

 

The Development Requires

by Vasily Kartashov

downloader

06/10 2017

0.0.2

0.0.2.0

Downloader Library

  Sources   Download

The Requires

 

The Development Requires

by Vasily Kartashov

downloader

21/09 2017

0.0.1

0.0.1.0

Downloader Library

  Sources   Download

The Requires

 

The Development Requires

by Vasily Kartashov

downloader