Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fixes Artisan serve command on Windows #43437

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

nunomaduro
Copy link
Member

This pull request fixes the serve command when being used on Windows.

Fixes #43433.

@nunomaduro nunomaduro requested a review from taylorotwell July 26, 2022 16:10
@taylorotwell taylorotwell merged commit cdb82eb into 9.x Jul 26, 2022
@taylorotwell taylorotwell deleted the fix/serve-command-on-windows branch July 26, 2022 16:15
@antonkomarev
Copy link
Contributor

I hope some day we will have env independent constant in PHP for \n

@JohnRoux
Copy link

This seems to have broken the serve command for me.
When I have a --host argument with subdomains, any page load at all on localhost results in this error:

 ErrorException 

  Undefined array key 0

  at vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php:252
    248▕                 preg_match('/\:(\d+)/', $parts[1], $matches);
    249▕ 
    250▕                 $request = $this->requestsPool[$matches[1]];
    251▕ 
  ➜ 252▕                 [$startDate, $file] = $request;
    253▕                 $formattedStartedAt = $startDate->format('Y-m-d H:i:s');
    254▕ 
    255▕                 unset($this->requestsPool[$matches[1]]);
    256▕ 

@nunomaduro
Copy link
Member Author

When I have a --host argument with subdomains, any page load at all on localhost results in this error:

Can you elaborate?

@JohnRoux
Copy link

Sorry, this isn't actually the right PR.
I've having the same problem as on this PR

Stock laravel install with Nova4 and trying to use --host seems to be giving me that same problem.
I'm not running windows either fwiw, running ubuntu 20.04

I ended up forceably downgrading to 9.20.0 to get my serve command working

@nunomaduro
Copy link
Member Author

You also have the issue using the latest version of Laravel? If yes, can you share the exact command with me?

@JohnRoux
Copy link

Yeah, same issue on latest 9.x most recently updated:

php artisan serve --host rouxtaccess.slackboard.localhost

@nicolaibaaring
Copy link

nicolaibaaring commented Jul 28, 2022

I have the same issue on Laravel version 9.22.1 and Windows 10. The command is php artisan serve but I'm loading a custom ServeCommand with the following settings:

    protected function getOptions()
    {
        return [
            ['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', 'sub.domain.site'],
            ['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 8088],
            ['no-reload', null, InputOption::VALUE_OPTIONAL, 'Instruct the built-in server to not reload the server when environment file changes.', false],
        ];
    }

The problem does not occur when there is no custom serve command, but if the same settings are set manually on the terminal command php artisan serve --host="sub.domain.site" --port=8088 , then the problem is the same.
The actual input for host and port do not matter. Any custom input will cause the problem.

I can create two (maybe) different versions of the error. One has the error Undefined array key 0 (on line 252) and the other one has the error Undefined array key XXXX (on line 250), where XXXX is the from the request
"[Thu Jul 28 12:55:28 2022] [nnnn::XXXX:nnnn:nnnn:nnnn]:NNNNN Closing"

I hope it helps the debugging.

@nunomaduro
Copy link
Member Author

Working on this - should be ready today.

@nunomaduro
Copy link
Member Author

@nicolaibaaring @JohnRoux can you test the contents of this pull request in your project? #43461.

@JohnRoux
Copy link

Hey, confirmed that it's working for me 🚀

I swapped out my laravel/framework in composer for this

"laravel/framework": "dev-fix/serve-command-with-host as 9.22.2",

And it doesn't have the serve problem on either of the two app's which 9.* currently breaks on

@nunomaduro
Copy link
Member Author

Waiting for your @nicolaibaaring feedback now.

@nicolaibaaring
Copy link

That also works on my side. I've tested on two projects too. Thanks for your efforts.

Ken-vdE pushed a commit to Ken-vdE/framework that referenced this pull request Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server stop caused by undefined array key
5 participants