laravel/framework · error · InvalidArgumentException

The seconds [$seconds] must be greater than zero.

Error message

The seconds [$seconds] must be greater than zero.

What it means

Thrown by ManagesFrequencies::repeatEvery() (src/Illuminate/Console/Scheduling/ManagesFrequencies.php:165) when $seconds <= 0. The sub-minute repeat feature (everySecond/everyFiveSeconds/...) divides the minute evenly and requires a positive interval.

Source

Thrown at src/Illuminate/Console/Scheduling/ManagesFrequencies.php:165

     * @return $this
     */
    public function everyThirtySeconds()
    {
        return $this->repeatEvery(30);
    }

    /**
     * Schedule the event to run multiple times per minute.
     *
     * @param  int<1, 59>  $seconds
     * @return $this
     *
     * @throws \InvalidArgumentException
     */
    protected function repeatEvery($seconds)
    {
        if ($seconds <= 0) {
            throw new InvalidArgumentException("The seconds [$seconds] must be greater than zero.");
        }

        if (60 % $seconds !== 0) {
            throw new InvalidArgumentException("The seconds [$seconds] are not evenly divisible by 60.");
        }

        $this->repeatSeconds = $seconds;

        return $this->everyMinute();
    }

    /**
     * Schedule the event to run every minute.
     *
     * @return $this
     */
    public function everyMinute()
    {

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Ensure seconds is a positive integer between 1 and 59.
  2. Guard user-supplied values: max(1, (int) $input).
  3. Use the named helpers (everySecond/everyFiveSeconds/...) for fixed intervals.
  4. If 0 means 'disabled', branch before calling the scheduler.

Example fix

// before
$event->repeatEvery($userSeconds);  // $userSeconds = 0

// after
$seconds = max(1, (int) $userSeconds);
if ($seconds > 0) {
    $event->repeatEvery($seconds);
}
Defensive patterns

Strategy: validation

Validate before calling

$seconds = (int) $input;
if ($seconds <= 0) {
    // skip scheduling or clamp to a positive value
}

Type guard

function isValidSeconds(int $s): bool
{
    return $s > 0 && $s < 60;
}

Try / catch

try {
    $event->repeatEvery($seconds);
} catch (\InvalidArgumentException $e) {
    // default to a known-good interval
    $event->everyMinute();
}

Prevention

When it happens

Trigger: Calling repeatEvery(0), repeatEvery(-5), or the public helpers everySecond() / everyFiveSeconds() with a value computed to <= 0. Also possible if a user-facing input flows into repeatEvery without sanitization.

Common situations: Dynamic code computing seconds from user input and passing 0; misconfigured tests; passing null which coerces to 0.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/fb1b7ffcbf0bbda2.json. Report an issue: GitHub.