---
title: "Using the API"
manual: "Warming"
version: "5.3"
permalink: "https://docs.typo3.org/permalink/eliashaeussler/typo3-warming:using-the-api@5.3"
source: "Usage/UsingTheAPI.rst"
rendered: "2026-11-05T08:37:00+00:00"
---

# Using the API {#using-the-api}

Besides the usage via the TYPO3 backend and the console commands,
there is also a public PHP API. It can be used to execute the cache
warmup directly in PHP code.

-   **class CacheWarmupService**

    -   *Fully qualified name:* `\EliasHaeussler\Typo3Warming\Service\CacheWarmupService`

    Service to run cache warmup for sites and pages.

    -   **warmup($sites, $pages, $limit, $strategy)**

        Run cache warmup for given sites and pages.

        -   *param array $sites:* List of site warmup requests.
        -   *param array $pages:* List of page warmup requests.
        -   *param int|null $limit:* Optional cache warmup limit.
        -   *param \\EliasHaeussler\\CacheWarmup\\Crawler\\Strategy\\CrawlingStrategy|null $strategy:* Optional crawling strategy.
        -   *returntype:* `\EliasHaeussler\Typo3Warming\Result\CacheWarmupResult`

## Example {#api-example}

```php
use EliasHaeussler\CacheWarmup;
use EliasHaeussler\Typo3Warming;
use TYPO3\CMS\Core;

$cacheWarmupService = Core\Utility\GeneralUtility::makeInstance(Typo3Warming\Service\CacheWarmupService::class);
$siteFinder = Core\Utility\GeneralUtility::makeInstance(Core\Site\SiteFinder::class);

$sites = [];
$pages = [];

// Create site warmup requests
foreach ($siteFinder->getAllSites() as $site) {
    $sites[] = new Typo3Warming\ValueObject\Request\SiteWarmupRequest($site);
}

// Create page warmup requests
foreach ([1, 2, 3] as $page) {
    $pages[] = new Typo3Warming\ValueObject\Request\PageWarmupRequest($page);
}

// Define optional cache warmup options
$limit = 100;
$strategy = new CacheWarmup\Crawler\Strategy\SortByPriorityStrategy();

// Run cache warmup for sites and pages
$result = $cacheWarmupService->warmup($sites, $pages, $limit, $strategy);

// Fetch crawling states
$failedUrls = $result->getResult()->getFailed();
$successfulUrls = $result->getResult()->getSuccessful();

// Fetch excluded URLs
$excludedUrls = $result->getExcludedUrls();
```
