> For the complete documentation index, see [llms.txt](https://docs.mobiledetect.net/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mobiledetect.net/home/the-constructor.md).

# The constructor

```php
$detect = new MobileDetect(?CacheInterface $cache = null, array $config = [])
```

The constructor can receive an optional cache class compatible with [`Psr\SimpleCache\CacheInterface`](https://github.com/php-fig/simple-cache/blob/master/src/CacheInterface.php)

The constructor can also receive optional `$config` variables as follows:

<table><thead><tr><th width="276">Variable name</th><th width="131">Default value</th><th>Description</th></tr></thead><tbody><tr><td><code>autoInitOfHttpHeaders</code></td><td><code>true</code></td><td>Auto-initialization on HTTP headers from <code>$_SERVER['HTTP...']</code>. Disable this if you're going for performance and you want to manually set the User-Agent via <code>$detect->setUserAgent(...)</code></td></tr><tr><td><code>maximumUserAgentLength</code></td><td><code>500</code></td><td>Maximum HTTP User-Agent value allowed.</td></tr><tr><td><code>cacheKeyFn</code></td><td><code>sha1</code></td><td>Method of encoding the cache key.</td></tr><tr><td><code>cacheTtl</code></td><td><code>86400</code></td><td>Default expiration date for the default <code>Cache</code> class implementation.</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mobiledetect.net/home/the-constructor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
