<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa" -->

---
title: Delete Expired Sessions in Laravel With a Scheduled Command
description: Laravel 13.39 adds a session:garbage-collect Artisan command that deletes expired database and file sessions on a schedule. Scheduling it hourly lets you set...
canonical: https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Delete Expired Sessions in Laravel With a Scheduled Command | daily.dev
og:description: Laravel 13.39 adds a session:garbage-collect Artisan command that deletes expired database and file sessions on a schedule. Scheduling it hourly lets you set...
og:url: https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa
og:image: https://api.daily.dev/og/posts/KQjeQYaQa.png
og:image:alt: Delete Expired Sessions in Laravel With a Scheduled Command
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Expired Sessions in Laravel With a Scheduled Command

**[Laravel News](https://daily.dev/sources/ln)** · 4 min read · 0 upvotes · 0 comments

## Summary

Laravel 13.39 adds a session:garbage-collect Artisan command that deletes expired database and file sessions on a schedule. Scheduling it hourly lets you set lottery to [0, 100] in config/session.php, so no web request runs the cleanup. The database and file drivers need this cleanup; redis, memcached, dynamodb, apc and cookie drivers expire sessions on their own. For multi-server setups, add onOneServer() when using the database driver. Apps on Laravel 13.38 or earlier can replicate this with a scheduled closure calling the session handler's gc() method.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://laravel-news.com/laravel-delete-expired-sessions>

## Questions this post answers

### How do I delete expired sessions automatically in Laravel 13.39?

Schedule the session:garbage-collect Artisan command, for example Schedule::command('session:garbage-collect')->hourly() in routes/console.php. It runs the same cleanup Laravel already triggers during some web requests but moves it off the request path. This only matters for the database and file session drivers; redis, memcached, dynamodb, apc, and cookie drivers expire sessions without any cleanup step.

_Developers tuning Laravel session cleanup can track framework changes like this on daily.dev._

### What does the session lottery setting do in Laravel's config/session.php?

The lottery option, formatted as [2, 100] by default, sets the odds that a request starting a session will run expired-session cleanup before reaching your route, and that request waits for it to finish. At 1,000 requests a minute this triggers roughly 20 cleanups a minute regardless of need; at low traffic cleanup may run less than once a day.

_Anyone tuning Laravel request latency can keep an eye on config changes like this via daily.dev._

### How do I run Laravel session garbage collection on a version older than 13.39?

On Laravel 13.38 and earlier, session:garbage-collect doesn't exist, so schedule a closure instead: Schedule::call(function () { app('session')->driver()->getHandler()->gc((int) config('session.lifetime') * 60); })->name('delete-expired-sessions')->hourly()->onOneServer(). This works on Laravel 11, 12, and 13, and a scheduled closure requires name() before onOneServer() or Laravel throws an exception.

_Teams on older Laravel versions can follow framework compatibility fixes like this on daily.dev._

## Similar posts on daily.dev

- [Scheduled Session Garbage Collection in Laravel 13.39](https://daily.dev/posts/scheduled-session-garbage-collection-in-laravel-13-39-skevw5rga) · Laravel News · 1 upvotes · 0 comments
- [Pruning Abandoned Carts](https://daily.dev/posts/pruning-abandoned-carts-gaa6lepzw) · Larablog · 0 upvotes · 0 comments
- [Laravel Task Scheduling & Automation: Simplify Cron Jobs with the Scheduler](https://daily.dev/posts/laravel-task-scheduling-automation-simplify-cron-jobs-with-the-scheduler-nqdiov7wv) · DEV · 2 upvotes · 0 comments
- [Storage Cache Store in Laravel 13.10.0](https://daily.dev/posts/storage-cache-store-in-laravel-13-10-0-r1lc1xf37) · Laravel News · 35 upvotes · 4 comments
- [The Laravel Scheduler Under the Hood](https://daily.dev/posts/the-laravel-scheduler-under-the-hood-dgtbvlorx) · W endell Adriel · 5 upvotes · 0 comments

---

Tags: [#database](https://daily.dev/tags/database), [#php](https://daily.dev/tags/php), [#authentication](https://daily.dev/tags/authentication), [#laravel](https://daily.dev/tags/laravel)

[View this post on daily.dev](https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Delete Expired Sessions in Laravel With a Scheduled Command","url":"https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa"},"datePublished":"2026-10-30T13:40:43.665Z","dateModified":"2026-10-30T13:41:11.229Z","description":"Laravel 13.39 adds a session:garbage-collect Artisan command that deletes expired database and file sessions on a schedule. Scheduling it hourly lets you set...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b9aeebdf310ca792c6ea8881d2139035?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b9aeebdf310ca792c6ea8881d2139035?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Laravel News","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Laravel News","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/ln","url":"https://daily.dev/sources/ln"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"database,php,authentication,laravel","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Laravel News","item":"https://daily.dev/sources/ln"},{"@type":"ListItem","position":3,"name":"Delete Expired Sessions in Laravel With a Scheduled Command"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/delete-expired-sessions-in-laravel-with-a-scheduled-command-kqjeqyaqa#faq","mainEntity":[{"@type":"Question","name":"How do I delete expired sessions automatically in Laravel 13.39?","acceptedAnswer":{"@type":"Answer","text":"Schedule the session:garbage-collect Artisan command, for example Schedule::command('session:garbage-collect')-\u003ehourly() in routes/console.php. It runs the same cleanup Laravel already triggers during some web requests but moves it off the request path. This only matters for the database and file session drivers; redis, memcached, dynamodb, apc, and cookie drivers expire sessions without any cleanup step. Developers tuning Laravel session cleanup can track framework changes like this on daily.dev."}},{"@type":"Question","name":"What does the session lottery setting do in Laravel's config/session.php?","acceptedAnswer":{"@type":"Answer","text":"The lottery option, formatted as [2, 100] by default, sets the odds that a request starting a session will run expired-session cleanup before reaching your route, and that request waits for it to finish. At 1,000 requests a minute this triggers roughly 20 cleanups a minute regardless of need; at low traffic cleanup may run less than once a day. Anyone tuning Laravel request latency can keep an eye on config changes like this via daily.dev."}},{"@type":"Question","name":"How do I run Laravel session garbage collection on a version older than 13.39?","acceptedAnswer":{"@type":"Answer","text":"On Laravel 13.38 and earlier, session:garbage-collect doesn't exist, so schedule a closure instead: Schedule::call(function () { app('session')-\u003edriver()-\u003egetHandler()-\u003egc((int) config('session.lifetime') * 60); })-\u003ename('delete-expired-sessions')-\u003ehourly()-\u003eonOneServer(). This works on Laravel 11, 12, and 13, and a scheduled closure requires name() before onOneServer() or Laravel throws an exception. Teams on older Laravel versions can follow framework compatibility fixes like this on daily.dev."}}]}
```

