# Ask your Laravel app why it cannot sleep

php artisan brewless:sleep asks every public page as a first visitor does, and names the rule each one breaks, so you know what wakes your container.

## In short

- A serverless container sleeps only after fifteen quiet minutes, so what decides whether it ever sleeps is how much of your site the edge answers by itself.
- `php artisan brewless:sleep` asks every public page through your own middleware, without cookies, and names the rule each page breaks.
- The commonest reason is a session, because a page that shows a CSRF token or puts anything in the session sends a cookie, and a shared cache never keeps an answer with a cookie.
- A page can answer differently on a developer machine than it does live, so the answer that counts comes from `brewless command production "brewless:sleep"`.
- `--strict` makes the command fail when a page cannot be kept, which turns it into a git hook or a pipeline step.

A serverless container sleeps only after a quiet spell: fifteen minutes at Scaleway, and every request that reaches it starts those fifteen minutes again. So the thing that decides whether it ever sleeps is not how busy your site is, but how much of it the edge answers by itself. One request a minute is enough to keep a container running day and night.

Knowing that does not tell you which of your pages is the problem. [Why your Laravel container never scales to zero](/blog/laravel-container-never-sleeps) explains the rules; this post is about the command that applies them to your own application, page by page, and tells you what to change.

## How do I find out what keeps my Laravel container awake?

Run `php artisan brewless:sleep`. The command comes with the `brewless/laravel` package, asks every public page the way a first visitor asks it, and names the rule each page breaks. Pages are grouped by reason, because on a real site hundreds of them share one.

## It asks your application, it does not read it

A linter that greps for `@csrf` would miss most of this. Whether the edge can keep a page depends on the answer your application gives, after every middleware, view composer and service provider has had its say.

So the command builds a request for each address on your own `APP_URL`, sends it through the application's HTTP kernel without a single cookie, and holds the answer against the same rules the package's edge middleware applies: the answer must be a 200, 301, 308, 404 or 410, set no cookie, start no session, set no `Cache-Control` of its own, vary on nothing but `Accept-Encoding`, and not have looked at who is signed in.

Nothing leaves the machine, and no container is woken. It is the judgement the edge makes, made locally.

It asks only what a visitor can reach: GET routes, without a required parameter in the address, not behind an `auth` middleware, and not the addresses of tooling such as `/_ops`, Telescope, Horizon or Livewire.

## What it prints

```bash
php artisan brewless:sleep
```

```text
 INFO What keeps this container awake.

 Edge keeps a page for ................................ 3600 seconds
 Guests without a session ............................. on
 Sessions in .......................................... database
 Queue on ............................................. sqs
 Asked in ............................................. production, on https://example.com

 Kept at the edge ..................................... 58 of 74 pages

 14 pages — it keeps a session, so the answer is this visitor's. A page that shows a CSRF
 token, or puts anything in the session, keeps one even when a guest has nothing in it
    /
    /pricing
    /contact
    and 11 more
 2 pages — the answer is a 302; the edge keeps 200, 301, 308, 404 and 410
    /docs
    /careers

 Every 60 seconds — Check pending payments, and every tick wakes the worker

 3 files your pages name have no ?v= — the edge fetches those from your container, not from
 the storage zone
    /favicon.ico
    /apple-touch-icon.png
    /img/logo.svg
```

The block at the top is the handful of settings that decide most of it, as the container really has them: how long the edge may keep a page, whether a guest without a cookie gets a session, where sessions and the queue live, and which environment answered.

## The reasons, and what to do about each

| What it says | What it usually is | What to do |
| --- | --- | --- |
| it keeps a session | A CSRF token on a page with no form of its own, often from a newsletter field or a modal in the layout | Send that form with `fetch()` and leave the token out, or move it to a page of its own. Wrap routes that need no session in `Route::withoutSession()` |
| it sets a cookie (…) | Analytics, a consent choice, a remembered locale | Set it from the browser, or on the one request that needs it, not on every page |
| it starts a session | Something writes to the session on a page that shows nothing from it | Find the write; a flash message or a "last visited" counter is enough |
| the answer is a 302 | A trailing slash, an old address, a locale redirect | Link to the address it ends on, or make a permanent redirect a 301 |
| it sets `Cache-Control` itself | A middleware or controller that chose its own header, which silently overrules `edge.cache` | Take it out where the page is the same for everybody; keep it where it is not |
| it varies on … | `Accept-Language`, or a header a middleware reads | The edge keeps one answer per address and understands no `Vary` but `Accept-Encoding`, so give each variant an address |
| it looked at who is signed in | `@auth` or `auth()->user()` in a layout, often for one menu item | Render that part from the browser, or accept that the page wakes the container |

Below the pages come two more things the command notices. Files your pages name without a `?v=` are fetched from your container instead of from the storage zone, so give every `<link>`, `<script>` and `<img>` an address with a version made from the file's content rather than from `filemtime()`. And scheduled work that repeats within the hour wakes your worker that often; daily or hourly is almost always enough.

## Ask production, not your laptop

A page can answer differently on a developer machine than it does live, and only the live answer decides what the edge keeps. The command says which environment answered, and tells you so when that is not production:

```bash
brewless command production "brewless:sleep"
```

> [!WARNING]
> A command has fifty seconds in your container. On a large site, ask in slices with `--path=/ --path=/pricing` rather than waiting for a report that never finishes.

## Keep it from coming back

One page with a form in the layout puts a session on the whole site again, and nobody notices until the bill arrives. `--strict` makes the command fail when a page cannot be kept, which is all a hook or a pipeline step needs:

```bash
php artisan brewless:sleep --strict
```

Run it against your own application, not production: it is the shape of your pages you want to catch, and the live answer is what you check after the deploy.

## Hand the list to a coding agent

Every reason has a fix in your own code, which makes this a good task for Claude Code, Codex or Cursor: give it the output and let it work through the list reason by reason. The [edge cache documentation](https://docs.brewless.eu/running/edge-cache) has a prompt to paste, and `brewless/laravel` ships a `brewless-sleep` skill that an agent loads when a task calls for one, written into your agent's skills folder by `php artisan boost:install` or `php artisan vendor:publish --tag=brewless-skills`.

Ask for a reason for every page it leaves as it is. Some pages are supposed to wake the container.

## What the command cannot see

Three things, and they are the ones that bite:

- **A monitor from outside.** An uptime check that polls every minute keeps your container awake on its own, and no amount of caching helps. Brewless never asks your application anything for that reason.
- **Addresses with a query string.** The edge keeps one copy per address, so `?utm_source=…` is its own copy and its own first visit. [Why `?utm_source` links wake your Laravel container](/blog/laravel-tracking-parameters-edge-cache) is about that.
- **What visitors really ask for.** The command knows your routes, not your traffic.

For the last one, the environment's page in the console has **What reaches the container**: the addresses of the last 24 hours that the edge did not answer itself, most first, read from the request log of its pull zone. The same list is in a terminal with `brewless wakes production`. Next to it, serverless usage shows how much of a period the container ran and how much it was scaled to zero, counted from Scaleway's own figures.

Judge a change there a day later, not in the hour you made it: a release empties the edge, so the hours after a deploy always look worse than a quiet day.

## In short

1. A container sleeps only after fifteen minutes without a request that reaches it.
2. `php artisan brewless:sleep` asks every public page as a first visitor does and names the rule it breaks.
3. A session on a page that shows nothing from it is the commonest reason, and usually a CSRF token in the layout.
4. The answer that counts is production's: `brewless command production "brewless:sleep"`.
5. Add `--strict` to a hook, then look at what reaches the container a day later.

## Frequently asked questions

### How do I find out what keeps my Laravel container awake?

Run `php artisan brewless:sleep` in the application. It asks every public page through your own middleware, as a first visitor asks it, holds the answer against the rules the edge follows, and reports the rule each page breaks, grouped by reason. Next to that it names the files your pages load without a version and the scheduled work that repeats within the hour.

### Does the command send requests to my site?

No. Every page is handled inside the process the command runs in, so nothing leaves the machine and no container is woken by it. Running it on production with `brewless command` does use your live container for those fifty seconds, but that is one deliberate wake, not a crawl of your site from outside.

### Which pages does it leave out?

Routes that are not GET, routes with a required parameter in the address, routes behind an `auth` middleware and the addresses of tooling such as `/_ops`, Telescope, Horizon and Livewire. A page only a signed-in visitor sees is never kept at the edge anyway, so asking it would say nothing.

### Is it bad that some pages keep a session?

No. A cart, a wizard or a form that needs a CSRF token is meant to reach your container, and those pages should keep their session. What costs you money is the page that could have been the same for everybody and quietly is not, because then every crawler and every link preview starts the fifteen minutes again.

### What if the command says edge.cache is 0?

Then the edge keeps nothing at all and every visitor reaches your container, whatever the rest of the report says. Set `edge.cache` in `brewless.yml` to how long a page may be kept, deploy, and run the command again.

Source: https://brewless.eu/blog/ask-your-laravel-app-why-it-cannot-sleep
