PHP Error Built in Server Invalid request (Unexpected EOF)

Asked

Viewed 1,030 times

6

Eventually on the console or cmd error appears Invalid request (Unexpected EOF), note that I understand what EOF means, which is Andnd Thef File, but I don’t understand why exactly this happens.

At first I thought it was something related to conflicts with IPV6, but I’m not sure now, note that I’m using a routing script, the result is something like:

PHP 5.6.14 Development Server started at Tue Oct 04 10:39:40 2016
Listening on http://localhost:9000
Document root is C:\Users\Guilherme\Documents\GitHub\inphinit
Press Ctrl-C to quit.
[Tue Oct 04 10:40:13 2016] ::1:62748 Invalid request (Unexpected EOF)
[Tue Oct 04 10:40:13 2016] ::1:62749 Invalid request (Unexpected EOF)

Note that the server does not stop working, I’m just curious to understand why this

Command is like this:

php -S localhost:9000 router.php

He’s like this basically:

<?php

$serverPath = realpath(dirname(__FILE__) . '/../../');
$serverPath = rtrim(strtr($serverPath, '\\', '/'), '/') . '/';

$path = urldecode(preg_replace('#\?(.*)$#', '', $_SERVER['REQUEST_URI']));
$path = ltrim($path, '/');

if (
    $path !== '' &&
    $path !== '/' &&
    strcasecmp($path, 'system') !== 0 &&
    stripos($path, 'system/') !== 0 &&
    file_exists($serverPath . $path)
) {
    return false;
}

echo 'Oi';

The problem seems to occur only when I use a routing script, I noticed the problem in windows, but I did not get to test in Unix-like environments and do not know if this occurs in them, I did the tests in:

  • Windows 8.1 x64
  • PHP 5.6.14 x64 and x86

I tested on two different machines

  • 1

    Apparently is a bug. Have you tried clearing your browser cache? or trying "private mode"?

  • @stderr I will try and I will even try a different browser than Chrome and I warn you :)

  • msm using 64-bit windows versions, its both php and apache installments must be 32-bit to prevent headaches.

  • @Tiagonet is not a problem with apache, the problem is with "php built-in server", and the problem occurs in php32bt and php64ibt, the situation is different.

  • @stderr just tested now, the problem occurs without the router too, so you don’t have what to fix in the router

1 answer

3

This seems to be an old PHP flaw, as can be seen here.

It’s just a warning message, it’s not something that will compromise the integrity of the application.

Invalid request (Unexpected EOF)

The message Invalid request (Unexpected EOF) indicates that a request has been made but no data has been received, as can be seen in the source code, this is handled in the function php_cli_server_recv_event_read_request:

static int php_cli_server_recv_event_read_request(php_cli_server *server, 
                                                  php_cli_server_client *client)
{
    char *errstr = NULL;
    int status = php_cli_server_client_read_request(client, &errstr);

    if (status < 0) {
        php_cli_server_logf("%s Invalid request (%s)", client->addr_str, errstr);
        efree(errstr);
        php_cli_server_close_connection(server, client);
        return FAILURE;
    } 

    return SUCCESS;
}

Message is launched when function output php_cli_server_client_read_request is negative, note below where it happens:

static int php_cli_server_client_read_request(php_cli_server_client *client, char **errstr)
{
    int nbytes_read;
    // ....
    nbytes_read = recv(client->sock, buf, sizeof(buf) - 1, 0);

    if (nbytes_read < 0) {
        int err = php_socket_errno();
        if (err == SOCK_EAGAIN) {
            return 0;
        }

        *errstr = php_socket_strerror(err, NULL, 0);
        return -1;

    } else if (nbytes_read == 0) { // Entra nessa condição
        *errstr = estrdup("Unexpected EOF");
        return -1;
    }   
    // ...
}

Patch

Here has a proposal (patch) to remove the message.

Causative

What might be causing these requests, might be, because you use Chrome, the prediction service to load pages faster, if you disable this option, the message probably won’t appear again.

To deactivate, do the following:

  • Click on inserir a descrição da imagem aquiSettings.
  • At the bottom, click on Show advanced settings.
  • In the section Privacy, clear the box next to Use a prediction service to load pages faster. inserir a descrição da imagem aqui

An alternative is to use incognito mode, the shortcut is CTRL + Shift + N.

Note: This can also happen in other browsers that have some optimization similar to Chrome.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.