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

ErrorException #53175

Closed
muzammil-umar-cd opened this issue Oct 15, 2024 · 13 comments · Fixed by #53178
Closed

ErrorException #53175

muzammil-umar-cd opened this issue Oct 15, 2024 · 13 comments · Fixed by #53178
Labels

Comments

@muzammil-umar-cd
Copy link

Laravel Version

Laravel Framework 11.28.0

PHP Version

PHP 8.2.12 (cli)

Database Driver & Version

No response

Description

Undefined array key 1

at vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:368
364▕ $line = str_replace(' ', ' ', $line);
365▕
366▕ preg_match($regex, $line, $matches);
367▕
➜ 368▕ return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
369▕ }
370▕
371▕ /**
372▕ * Get the request port from the given PHP server output.

1 vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:368
Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap{closure}("Undefined array key 1", "E:\LaravelChat\real-time-chat\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php")

2 vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:297
Illuminate\Foundation\Console\ServeCommand::getDateFromLine("[Wed Oct 16 01:37:06 2024] 127.0.0.1:58025 Accepted")

Steps To Reproduce

vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand

@muzammil-umar-cd
Copy link
Author

I'm getting this error after creating a fresh laravel project

@ludovicmeurot
Copy link

I have the exact same error with the same context.

While not ideal, you can work around the issue by running the internal PHP server directly while waiting for the fix: php -S localhost:8000 -t .\public\

@Zeinot
Copy link

Zeinot commented Oct 15, 2024

Same here
windows 10 installing laravel using powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://php.new/install/windows'))

and then

laravel new example-app

 ErrorException 

 Undefined array key 1

 at vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:368
   364▕         $line = str_replace('  ', ' ', $line);
   365▕
   366▕         preg_match($regex, $line, $matches);
   367▕
 ➜ 368▕         return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
   369▕     }
   370▕
   371▕     /**
   372▕      * Get the request port from the given PHP server output.

 1   vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:368
     Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("Undefined array key 1", "C:\Users\Win10\Desktop\new-livewire\example-app\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php")

 2   vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:297
     Illuminate\Foundation\Console\ServeCommand::getDateFromLine("[Tue Oct 15 23:51:39 2024] 127.0.0.1:56009 Accepted")


  Whoops\Exception\ErrorException 

 Undefined array key 0

 at vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:320
   316▕                             microtime(true),
   317▕                         ];
   318▕                     }
   319▕
 ➜ 320▕                     [$startDate, $file, $startMicrotime] = $this->requestsPool[$requestPort];
   321▕
   322▕                     $formattedStartedAt = $startDate->format('Y-m-d H:i:s');
   323▕
   324▕                     unset($this->requestsPool[$requestPort]);

 1   vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:320
     Whoops\Run::handleError("Undefined array key 0", "C:\Users\Win10\Desktop\new-livewire\example-app\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php")

 2   vendor\laravel\framework\src\Illuminate\Collections\Traits\EnumeratesValues.php:257
     Illuminate\Foundation\Console\ServeCommand::Illuminate\Foundation\Console\{closure}("[Tue Oct 15 23:51:39 2024] 127.0.0.1:56009 Closing")



@crynobone
Copy link
Member

Can anyone with Windows update .env with following changes and try again:

-PHP_CLI_SERVER_WORKERS=4
+PHP_CLI_SERVER_WORKERS=1

@Zeinot
Copy link

Zeinot commented Oct 15, 2024

crynobone
oh WOW that did work

-PHP_CLI_SERVER_WORKERS=4
+PHP_CLI_SERVER_WORKERS=1

why does that cause an issue ?

@crynobone
Copy link
Member

@Zeinot Submitted and explained in PR #53178

@RahmatPrakoso276
Copy link

Can anyone with Windows update .env with following changes and try again:

-PHP_CLI_SERVER_WORKERS=4
+PHP_CLI_SERVER_WORKERS=1

thanks it works

@CodeWithPranta
Copy link

I solved it by changing code: vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:368

   ```

// return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);

    if (isset($matches[1])) {
        return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
    }

    // Handle the error or provide a default value
    return Carbon::now();

@Jrhero14
Copy link

I got same error to when create new laravel project

@matrixcoding101
Copy link

i am also getting same error with fresh laravel install. when i changed .env PHP_CLI_SERVER_WORKERS value 4 to 1 then its works.
-PHP_CLI_SERVER_WORKERS=4
+PHP_CLI_SERVER_WORKERS=1

my question is why this error occurred while fresh laravel install?

@BrayamFlorez
Copy link

También recibo el mismo error con la nueva instalación de Laravel. Cuando cambié el valor 4 de PHP_CLI_SERVER_WORKERS en .env a 1, funcionó. -PHP_CLI_SERVER_WORKERS=4 +PHP_CLI_SERVER_WORKERS=1

Mi pregunta es ¿por qué se produjo este error durante la instalación nueva de Laravel?

pareciera ser problema de versiones, sin embargo al usar el truco lo que hacemos es bajar la cantidad de workers comprometiendo el rendimiento, es mucho mejor alternativa modificar el metodo getDateFromLine($line) en el archivo ServeCommand.php, al fina en el return reemplazalo por:

if (isset($matches[1])) {
return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
}

// Handle the error or provide a default value
return Carbon::now();

@m00n3r-dev
Copy link

Can anyone with Windows update .env with following changes and try again:

-PHP_CLI_SERVER_WORKERS=4
+PHP_CLI_SERVER_WORKERS=1

its works. thnks ❤

@farinchan
Copy link

Can anyone with Windows update .env with following changes and try again:

-PHP_CLI_SERVER_WORKERS=4
+PHP_CLI_SERVER_WORKERS=1

its works, Thanks man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.