Error PHP Built in Server Invalid request (Unexpected EOF)

5

Eventually in the console or cmd the error Invalid request (Unexpected EOF) appears, note that I understand what EOF means, which is E nd O f F ile, but I do not understand why exactly this occurs.

At first I thought it was something related to conflicts with IPV6, but I'm not sure of this now, notice 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

The command looks like this:

php -S localhost:9000 router.php

It looks like this:

<?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 only occur when I use a routing script, I noticed the problem in windows, but I did not get to test in unix-like environments and I do not know if this happens in them,

  • Windows 8.1 x64
  • PHP 5.6.14 x64 and x86

I tested two different machines

    
asked by anonymous 04.10.2016 / 15:57

1 answer

2

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

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

Invalid request (Unexpected EOF)

The Invalid request (Unexpected EOF) message 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 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;
}

The message is posted when the result of the % with_% / a> is negative, note below where this 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.

Causer

What might be causing these requests, perhaps because you use Chrome, the forecasting service to load pages faster, if you disable this option, the message will probably not appear again.

To disable, do the following:

  • Click on ➝Settings.
  • Atthebottom,clickShowadvancedsettings.
  • InthePrivacysection,unchecktheboxnexttoUseapredictionservicetoloadpagesfaster.

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

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

14.10.2016 / 14:56