environment = $environment; } /** * Runs the scheduled tasks (poor man's cron) after the HTTP response has been sent. * * Encapsulates the deferred-execution orchestration: it disables the user-abort and * execution-time limits, runs Laravel's `schedule:run` command through the console kernel, * and registers a shutdown function that logs the scheduler output when debug mode is enabled. * * @return int The exit code returned by the `schedule:run` command. * * @api */ public function runScheduledTasks(): int { ignore_user_abort(true); set_time_limit(0); $output = new BufferedOutput; $consoleKernel = app()->make(ConsoleKernel::class); $result = $consoleKernel->call('schedule:run', [], $output); register_shutdown_function(function () use ($output) { if ($this->environment->debug) { Log::info('Cron Schedule Output: '.$output->fetch()); } }); return $result; } }