Limits | crawler-go | Spatie       

 SPATIE  

crawler-go
==========

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Crawler-go](https://spatie.be/docs/crawler-go/v1)  Configuring-the-crawler  Limits

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/crawler-go/v1) 

  Limits    
- [ Introduction ](https://spatie.be/docs/crawler-go/v1/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/crawler-go/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/crawler-go/v1/questions-issues)
- [ About us ](https://spatie.be/docs/crawler-go/v1/about-us)
- [ Releasing ](https://spatie.be/docs/crawler-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/crawler-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/crawler-go/v1/support-us)

Basic usage
-----------

- [ Your first crawl ](https://spatie.be/docs/crawler-go/v1/basic-usage/starting-your-first-crawl)
- [ Crawl responses ](https://spatie.be/docs/crawler-go/v1/basic-usage/handling-crawl-responses)
- [ Using observers ](https://spatie.be/docs/crawler-go/v1/basic-usage/using-observers)
- [ Collecting URLs ](https://spatie.be/docs/crawler-go/v1/basic-usage/collecting-urls)
- [ Filtering URLs ](https://spatie.be/docs/crawler-go/v1/basic-usage/filtering-urls)
- [ Testing ](https://spatie.be/docs/crawler-go/v1/basic-usage/testing)
- [ Tracking progress ](https://spatie.be/docs/crawler-go/v1/basic-usage/tracking-progress)

Configuring the crawler
-----------------------

- [ Concurrency &amp; throttling ](https://spatie.be/docs/crawler-go/v1/configuring-the-crawler/crawl-behavior)
- [ Limits ](https://spatie.be/docs/crawler-go/v1/configuring-the-crawler/setting-crawl-limits)
- [ Extracting resources ](https://spatie.be/docs/crawler-go/v1/configuring-the-crawler/extracting-resources)
- [ Configuring requests ](https://spatie.be/docs/crawler-go/v1/configuring-the-crawler/configuring-requests)
- [ Response filtering ](https://spatie.be/docs/crawler-go/v1/configuring-the-crawler/handling-responses)
- [ Respecting robots.txt ](https://spatie.be/docs/crawler-go/v1/configuring-the-crawler/respecting-robots-txt)

Advanced usage
--------------

- [ JavaScript rendering ](https://spatie.be/docs/crawler-go/v1/advanced-usage/rendering-javascript)
- [ Custom link extraction ](https://spatie.be/docs/crawler-go/v1/advanced-usage/extracting-custom-links)
- [ Custom request handlers ](https://spatie.be/docs/crawler-go/v1/advanced-usage/custom-request-handlers)
- [ Crawling across requests ](https://spatie.be/docs/crawler-go/v1/advanced-usage/crawling-across-requests)
- [ Custom crawl queue ](https://spatie.be/docs/crawler-go/v1/advanced-usage/using-a-custom-crawl-queue)
- [ Graceful shutdown ](https://spatie.be/docs/crawler-go/v1/advanced-usage/graceful-shutdown)

 Limits
======

###  On this page 

1. [ Crawl depth ](#content-crawl-depth)
2. [ Crawl and time limits ](#content-crawl-and-time-limits)
3. [ Using the total crawl limit ](#content-using-the-total-crawl-limit)
4. [ Using time limits ](#content-using-time-limits)

By default, the crawler continues until it has crawled every page it can find. This can cause issues in environments with time or resource limits.

Crawl depth
-----------------------------------------------------------------------------------------

Set `Config.MaxDepth = 2` to limit how deep the crawler goes. Depth 0 fetches only the start URL. Depth 1 also fetches its direct links. The default -1 is unlimited. URLs at the maximum depth are fetched, but their children are not queued. First discovery wins, which need not be the shortest path during a concurrent crawl.

Crawl and time limits
-----------------------------------------------------------------------------------------------------------------------

OptionMeaning`Limit`Maximum URL attempts across executions using the same queue`LimitPerExecution`Maximum URL attempts in this execution`TimeLimit`Maximum elapsed time across executions using the same queue`TimeLimitPerExecution`Maximum elapsed time in this executionLimits default to -1. Zero is a real limit. Durations use `time.Duration`, not integer seconds. When limits combine, the tighter remaining budget wins.

Using the total crawl limit
-----------------------------------------------------------------------------------------------------------------------------------------

```
c.Queue = queue
c.Limit = 10
c.LimitPerExecution = 5
```

Reusing `queue` processes up to five URLs on the first execution, up to five on the second, and no more after the total reaches ten. Every claimed job reserves its slot before it starts, so concurrency does not overshoot the configured limit. Retries are part of one job.

Successful requests, failures and noindex responses consume slots. URLs refused before fetching do not consume this execution's slots. The total budget on a resumed queue uses its processed count, including entries skipped after a policy change. Cancelled unfinished claims return to pending and can be attempted again.

Using time limits
-----------------------------------------------------------------------------------------------------------

```
c.Queue = queue
c.TimeLimit = time.Minute
c.TimeLimitPerExecution = 30 * time.Second
```

Elapsed time includes initialization, callbacks, retries and delays. The queue stores it after `Start` returns. A process crash can lose the latest execution's elapsed time. Limits cancel in-flight HTTP work and return unfinished claims to pending. They do not wait for requests to finish normally. Custom transports and renderers must honor context cancellation, and blocking callbacks can delay shutdown.

Combine count, depth and time limits as needed. See [crawling across requests](/docs/crawler-go/v1/advanced-usage/crawling-across-requests) for storing the queue.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
