Skip to content

php leaf serve fails to start server on Windows (non-concurrent mode) #32

@ZeeshanX4

Description

@ZeeshanX4

Bug Description
When running php leaf serve on Windows without Vite/Redis/Jobs detected, the server fails to start. The command displays "Happy gardening 🍁" but the server never actually runs, and localhost:5500 returns ERR_CONNECTION_REFUSED.

Root Cause
In vendor/leafs/mvc-core/src/Commands/ServeCommand.php at line
$this->writeln(shell_exec($this->buildPhpServerCommand()) ?? "");

The problem: shell_exec() is designed for commands that complete and return output. When used with php -S (a long-running blocking process), it either:

Blocks indefinitely waiting for the process to finish (which never happens btw)
On Windows, starts the process and immediately terminates it when shell_exec() returns

This is why the server appears to start but isn't actually running.

Why Concurrent Mode Works
When Vite/Redis/Jobs are detected, the command uses:
sprout()->process("npx concurrently...")->run();

This properly handles long-running processes and streams output in real-time.

Steps to Reproduce
Install fresh Leaf MVC on Windows
Don't install Vite/Redis/Jobs (so concurrent mode isn't triggered)
Run php leaf serve
See "Happy gardening 🍁" message
Try to access http://localhost:5500
Get ERR_CONNECTION_REFUSED

Workaround
Use native PHP server directly:

php -S localhost:8000 -t public

Suggested Fix
Replace shell_exec() with proper process execution that keeps the process alive

Environment
OS: Windows 11
PHP Version: 8.2.29
Leaf MVC: v4.7.1
leafs/mvc-core: v4.7.1

Additional Context
This issue only affects Windows. On Linux/Mac, the behavior may be different due to how shell_exec() handles process spawning. There are issues with Laravel herd as well when the app env is in local or testing, only production works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions