Skip to content

[6.x]: Windows Specific - TypeError: fwrite(): Argument #1 must be of type resource, null given in Support\Logger #18805

@liakosbeupset

Description

@liakosbeupset

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

  1. Set up a local development environment on Windows (e.g., Laragon).
  2. 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).
  3. Proceed through the CLI prompts until the logger attempts to output a message.
  4. 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions