Asked 1 month ago by MeteorRanger970
How Can I Debug Statamic’s AppServiceProvider Halting Laravel’s Bootstrapping Process?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by MeteorRanger970
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
During an upgrade from Laravel 10 to 11 and Statamic 4 to 5, I noticed that some service providers aren’t booting during app startup—only after the kernel is called.
For context, the package ylsideas/feature-flags
registers a macro (skipWithoutFeature
) on the Event
facade for use in the kernel schedule. However, this macro isn’t registered when Statamic’s service provider executes during bootstrapping. Tracing through vendor files led me to vendor/laravel/framework/src/Illuminate/Foundation/Application::boot
, where the process stops at the following line in Statamic’s provider:
PHP$this->app->make(Schedule::class)->job(new HandleEntrySchedule)->everyMinute()
No exception is thrown or logged—catching the call in a try/catch produces no errors and no execution occurs after this line, preventing further service providers from booting. Once the kernel is fully registered and the macro is applied, the issue disappears.
What could be causing this bootstrapping halt, and how can I debug it when there is no catchable exception or log entry? Please advise on potential debugging strategies or changes in boot order that might resolve this timing issue.
Comments 0
•Answers 2
•Views 48
Answer by TychoAI Agent • 1 month ago
Below is one explanation that fits what you’re seeing in Laravel 11 with Statamic 5:
In Laravel 11 the bootstrapping process and the timing of when service providers run has shifted slightly. In your case the Statamic service provider is calling:
PHP$this->app->make(Schedule::class)->job(new HandleEntrySchedule)->everyMinute();
This call happens during early bootstrapping – before the kernel is fully registered. Meanwhile, your package (ylsideas/feature-flags) registers a macro (skipWithoutFeature on the Event facade) that the scheduling code ultimately ends up needing later in the lifecycle. When the call to schedule a job is made before the macro is available, it does not hit any catchable exception or log because it is essentially operating in a phase where things aren’t “ready” (or the dependency isn’t resolved yet).
This issue is compounded by the fact that an early resolution (making the Schedule instance too soon) may be causing part of the boot process to “freeze” silently. The vendor’s use of early scheduling may be triggering a fatal PHP error—or a misbehaving call sequence—that does not produce a normal exception when using try/catch.
Since nothing is logging or throwing a catchable exception, consider the following debugging steps:
Add Logging or Debug Breaks in the Service Provider
Temporarily modify the problematic service provider (or override it in your own service provider if possible) to log messages on entry and exit. For example:
PHP// In Statamic’s AppServiceProvider (or your override) Log::debug('Before scheduling HandleEntrySchedule'); $schedule = $this->app->make(Schedule::class); Log::debug('After instantiating Schedule'); $schedule->job(new HandleEntrySchedule)->everyMinute(); Log::debug('After scheduling job');
Enable Xdebug or a Similar Debugger
Use Xdebug to set breakpoints in the vendor code (especially around Application::boot and the Statamic provider method). This will allow you to step through and see exactly where execution halts.
Set a Custom Error Handler
Since the issue might be causing a fatal error that isn’t caught by traditional exception handling, try setting up a custom error or shutdown handler using PHP’s set_error_handler
or register_shutdown_function
to catch any low-level errors that may be occurring.
Review Service Provider Order and Macro Registration Timing
Check if reordering the booting of the packages or ensuring that the macro is registered earlier makes any difference. It might be necessary to delay the job scheduling until after the kernel (and thus the macro) is fully registered. Often scheduling is better placed within the Console Kernel’s schedule
method instead of the service provider boot method.
What you’re likely seeing is a bootstrapping timing issue introduced by Laravel 11’s updated lifecycle. The problematic line in Statamic’s AppServiceProvider calls an early resolution of the Schedule instance before your macro is registered. This can cause a silent failure (or even a fatal error that bypasses typical logging) during the boot process. Debugging this scenario will require inserting logging or breakpoints, enabling a custom error handler, and perhaps revisiting when and where scheduling is performed.
These steps should help pinpoint why execution stops and clarify whether adjusting the boot order or deferring schedule registration is needed.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by StarlitResearcher557 • 1 month ago
This was caused by a conflict of bootstrapping order between two packages.
The vendor/statamic/cms/src/Providers/AppServiceProvider.php
provider will run first, appending a task to the vendor/laravel/framework/src/Illuminate/Console/Scheduling/Schedule.php
class.
The vendor/ylsideas/feature-flags/src/FeatureFlagsServiceProvider.php
provider runs second and applies a macro for use within app/Console/Kernel.php
.
When the macro is used, because the FeatureFlagsServiceProvider
has not yet been booted, the call to $this->app->make(Schedule::class)
will throw an exception and therefore stop further service providers from being booted.
To fix this issue, within the app/Providers/AppServiceProvider::register
method I manually boot this service provider first:
PHP$this->app->booting(function(Application $app) { $app->make(FeatureFlagsServiceProvider::class, ['app' => $app])->boot(); });
This then makes the macro available to the facade, preventing any issues in the initial service provider.
No comments yet.
No comments yet.