Skip to content

Create a custom crawler ​

Crawlers are the core component of the library. They are used to perform the actual requests for all configured URLs to warm up their website caches. Each crawler must implement EliasHaeussler\CacheWarmup\Crawler\Crawler:

php
namespace Vendor\Crawler;

use EliasHaeussler\CacheWarmup;

final class MyCustomCrawler implements CacheWarmup\Crawler\Crawler
{
    // ...
}

Method Reference ​

The default crawler describes the following method:

crawl ​

When this method is called, the given list of URLs should be warmed up.

php
namespace Vendor\Crawler;

use EliasHaeussler\CacheWarmup;
use Psr\Http\Message; 

final class MyCustomCrawler implements CacheWarmup\Crawler\Crawler
{
    public function crawl(array $urls): CacheWarmup\Result\CacheWarmupResult
    { 
        $result = new CacheWarmup\Result\CacheWarmupResult(); 
​
        foreach ($urls as $url) { 
            if ($this->warmUp($url)) { 
                $crawlingResult = CacheWarmup\Result\CrawlingResult::createSuccessful($url); 
            } else { 
                $crawlingResult = CacheWarmup\Result\CrawlingResult::createFailed($url); 
            } 
​
            $result->addResult($crawlingResult); 
        } 
​
        return $result; 
    } 
​
    private function warmUp(Message\UriInterface $url): bool
    { 
        // ...
    } 
}

Released under the GNU General Public License 3.0 (or later)