hollodotme / fast-cgi-client

A PHP fast CGI client for sending requests (a)synchronously to PHP-FPM
Other
551 stars 34 forks source link

ForbiddenException: Not in white list ? #3

Closed sandrokeil closed 7 years ago

sandrokeil commented 7 years ago

I send 10 requests async and save the corresponding request id in an array. Then I use a loop over the ids to get the content, but only the content of the first id is received. After that I got the error fatal error: Uncaught hollodotme\FastCGI\Exceptions\ForbiddenException: Not in white list. Check listen.allowed_clients.

Here is a test script

 $ids = [];

for($i=0; $i<10; $i++) {
    $requestId = $client->sendAsyncRequest(
        [
            'GATEWAY_INTERFACE' => 'FastCGI/1.0',
            'REQUEST_METHOD'    => 'POST',
            'SCRIPT_FILENAME'   => '/var/www/src/socket.php',
            'SERVER_SOFTWARE'   => 'hollodotme/fast-cgi-client',
            'REMOTE_ADDR'       => '127.0.0.1',
            'REMOTE_PORT'       => '9985',
            'SERVER_ADDR'       => '127.0.0.1',
            'SERVER_PORT'       => '80',
            'SERVER_NAME'       => 'your-server',
            'SERVER_PROTOCOL'   => 'HTTP/1.1',
            'CONTENT_TYPE'      => 'application/x-www-form-urlencoded',
            'CONTENT_LENGTH'    => mb_strlen( $body )
        ],
        $body
    );
    $ids[] = (int) $requestId;

    echo "Request sent, got ID: " . var_export($requestId, true);
}

foreach ($ids as $id) {
        $response = $client->waitForResponse(
            $id,     # The request ID
        6000            # Optional timeout to wait for response,
    );

    var_dump($response);
}

Any ideas?

sandrokeil commented 7 years ago

Oh, I just have to use a persistent socket connection.

$connection = new UnixDomainSocket(
    'unix:///var/run/php7-fpm.sock',  # Socket path to php-fpm
    15000,                                   # Connect timeout in milliseconds (default: 5000)
    15000,                                   # Read/write timeout in milliseconds (default: 5000)
    true,                                  # Make socket connection persistent (default: false)
    true                                   # Keep socket connection alive (default: false)
);