/lab

Small tools from the work I do every day.

Built for poking at. Everything runs in your browser or against this site's own endpoints, and nothing you do here is stored.

01 · GET /api/me

See exactly what your browser sends.

Every debugging session starts with “what did the server actually receive?” Send a real GET /api/me and read it back.

❯ curl utsavsomaiya.in/api/me

// press send. the server replies with exactly what it received from you.

02 · schedule

Read any cron line or Laravel schedule.

Paste a cron expression like 0 9 * * 1-5 or a Laravel chain like ->weekdays()->dailyAt('09:00'). Get it in plain English, the next runs in your time zone, and a map of the week.

At 09:00, on Monday through Friday.

cron 0 9 * * 1-5tz UTC

  1. next 8 runs
  2. 1in 28h
  3. 2in 2d
  4. 3in 3d
  5. 4in 4d
  6. 5in 5d
  7. 6in 8d
  8. 7in 9d
  9. 8in 10d

the next 7 days, hour by hour5 runs

00061218
Mon
Tue
Wed
Thu
Fri
Sat
Sun

03 · queue:work

Watch a queue fail, retry and recover.

--tries, --backoff and the number of workers decide whether a bad minute becomes an incident. Drag the sliders and see why.

❯ php artisan queue:work --tries=3 --backoff=3 × 3

pending 0

empty

workers 3

  • worker 1idle
  • worker 2idle
  • worker 3idle

backoff 0

none
processed
0
retried
0
failed_jobs
0
throughput
0.0/s

select * from failed_jobs order by id desc limit 4;

(0 rows)

Try it: raise the failure rate and drop --tries to 1, and watch failed_jobs fill up. Then add workers and a backoff, and see the queue drain while retries recover. Simulated in your browser.

04 · N+1

Watch one innocent loop send a query per row.

The most common Laravel performance bug hides in a Blade loop. Flip between Post::all() and Post::with('author')->get() and watch the query log.

PostController.php · index.blade.php

// controller
$posts = Post::all();

{{-- view --}}
@foreach ($posts as $post)
    {{ $post->author->name }}
@endforeach

// each ->author fires its own query: 50 posts, 50 extra queries

DB::listen · query log

    0 / 51 queries · 0ms waiting on the database

    lazy
    51 queries · 204ms
    eager
    2 queries · 8ms

    Catch it before production: add Model::preventLazyLoading(! app()->isProduction()); to AppServiceProvider::boot() and every lazy load throws in development. Query counts are exact; the timing is simulated at the round trip you pick.