What happened?
Description
When running long-running tasks or complex installation commands (such as php artisan craft:install for Craft CMS 6) on a Windows environment, the command crashes with a TypeError regarding fwrite().
This happens because Windows environments do not support pcntl_fork, forcing Laravel Prompts to fall back to static rendering mode. Under certain conditions in this mode, the internal Logger is instantiated without a valid socket. In Laravel\Prompts\Support\Logger::write(), there is no validation to ensure that the $this->socket property is actually a valid resource before passing it to fwrite(), leading to a fatal crash in PHP 8+.
Steps to reproduce
- Set up a local development environment on Windows (e.g., Laragon).
- Install a package that relies on Laravel Prompts and triggers long-running tasks or fallback static rendering mode (such as installing Craft CMS 6 Alpha via
php artisan craft:install).
- Proceed through the CLI prompts until the logger attempts to output a message.
- The CLI script crashes with a
TypeError.
Expected behavior
The Logger should fail gracefully or silently ignore log writes if a valid socket resource is not available in the current rendering mode, allowing the underlying task to complete without crashing.
Actual behavior
The application crashes with the following fatal error:
TypeError
fwrite(): Argument #1 ($stream) must be of type resource, null given
Proposed Fix (src/Support/Logger.php):
Add a null-check guard at the top of the write() method:
protected function write(string $message, ?string $type = null): void
{
if (! $this->socket) {
return;
}
if ($type !== null) {
fwrite($this->socket, $this->prefix($type, $message).PHP_EOL);
} else {
fwrite($this->socket, $message.PHP_EOL);
}
}
Craft CMS version
6.0.0
PHP version
8.5.6
Operating system and version
Microsoft Windows 10 Pro (Version 10.0.19045)
Database type and version
MySQL 8.4.3
Image driver and version
No response
Installed plugins and versions
What happened?
Description
When running long-running tasks or complex installation commands (such as
php artisan craft:installfor Craft CMS 6) on a Windows environment, the command crashes with aTypeErrorregardingfwrite().This happens because Windows environments do not support
pcntl_fork, forcing Laravel Prompts to fall back to static rendering mode. Under certain conditions in this mode, the internalLoggeris instantiated without a valid socket. InLaravel\Prompts\Support\Logger::write(), there is no validation to ensure that the$this->socketproperty is actually a valid resource before passing it tofwrite(), leading to a fatal crash in PHP 8+.Steps to reproduce
php artisan craft:install).TypeError.Expected behavior
The
Loggershould fail gracefully or silently ignore log writes if a valid socket resource is not available in the current rendering mode, allowing the underlying task to complete without crashing.Actual behavior
The application crashes with the following fatal error:
Proposed Fix (
src/Support/Logger.php):Add a null-check guard at the top of the
write()method:Craft CMS version
6.0.0
PHP version
8.5.6
Operating system and version
Microsoft Windows 10 Pro (Version 10.0.19045)
Database type and version
MySQL 8.4.3
Image driver and version
No response
Installed plugins and versions