-2

I was running a laravel server using php artisan serve --host <my-public-ip> --port 80 when suddenly my server crashed with this error:

Undefined array key 60196

  at D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:263
    259▕
    260▕                 $this->requestsPool[$requestPort][1] = trim(explode('[200]: GET', $line)[1]);
    261▕             } elseif (str($line)->contains(' Closing')) {
    262▕                 $requestPort = $this->getRequestPortFromLine($line);
 ➜ 263▕                 $request = $this->requestsPool[$requestPort];
    264▕
    265▕                [$startDate, $file] = $request;
    266▕
    267▕                $formattedStartedAt = $startDate->format('Y-m-d H:i:s');

  1   D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:263
      Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("Undefined array key 60196", "D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php")

  2   D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Collections\Traits\EnumeratesValues.php:236
      Illuminate\Foundation\Console\ServeCommand::Illuminate\Foundation\Console\{closure}("[Sat Feb 18 12:51:14 2023] 25.66.139.15:60196 Closing")

What may have caused this issue and what preventative measures can be taken to avoid its recurrence?

Two
  • 512
  • 4
  • 17
  • 1
    I don't think this is related to my question – Abdulwahab Almestekawy Feb 18 '23 at 11:38
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12770836#12770836) – Jaquarh Feb 18 '23 at 12:26
  • @Jaquarh I know what does "undefined array key" mean. I am asking about why is `$requestPort` not found inside `$this->requestsPool` array which seems to be built in Laravel framework itself (not my code). – Abdulwahab Almestekawy Feb 18 '23 at 12:29
  • Give a [minimalistic reproduceable example](https://stackoverflow.com/help/minimal-reproducible-example), what does `$this->requestsPool` contain during runtime before the key is passed? What debug have you done, if any at all? The issue here is simple, the key being passed does not exist in the array (check the array, ensure the data is what you expect) - this is not a code writing service. – Jaquarh Feb 18 '23 at 12:40
  • I'm not sure if I can reproduce this error. Debugging seems very difficult because it's a built-in code (like a black box for me). – Abdulwahab Almestekawy Feb 18 '23 at 12:47
  • You have not included the full stack trace, the vendor file is probably not even the issue but the cause of the exeception that you're assuming is the problem. You should read or at least provide the **full stack trace** that by the looks of your OP is likely a custom Laravel command with code that isn't working. – Jaquarh Feb 18 '23 at 12:53

1 Answers1

0

Have you tried debbuging the content of that array $this->requestsPool using die dump function such as

dd($this->requestPool);

Check if the key exist

Two
  • 512
  • 4
  • 17