adoy / PHP-FastCGI-Client

Lightweight, single file, FastCGI client for PHP
MIT License
302 stars 61 forks source link

Error #22

Closed CatAnonymous closed 4 years ago

CatAnonymous commented 4 years ago

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /usr/local/openresty/nginx/html/php/src/Adoy/FastCGI/Client.php on line 267

Warning: fsockopen(): unable to connect to unix:/var/run/php/php7.4-fpm.sock:-1 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /usr/local/openresty/nginx/html/php/src/Adoy/FastCGI/Client.php on line 267

Fatal error: Uncaught Exception: Unable to connect to FastCGI application: php_network_getaddresses: getaddrinfo failed: Name or service not known in /usr/local/openresty/nginx/html/php/src/Adoy/FastCGI/Client.php:271 Stack trace: #0 /usr/local/openresty/nginx/html/php/src/Adoy/FastCGI/Client.php(474): Adoy\FastCGI\Client->connect() #1 /usr/local/openresty/nginx/html/php/src/Adoy/FastCGI/Client.php(451): Adoy\FastCGI\Client->async_request() #2 /usr/local/openresty/nginx/html/php/test.php(13): Adoy\FastCGI\Client->request() #3 {main} thrown in /usr/local/openresty/nginx/html/php/src/Adoy/FastCGI/Client.php on line 271
CatAnonymous commented 4 years ago
<?php

require 'src/Adoy/FastCGI/Client.php';

use Adoy\FastCGI\Client;

// Existing socket, such as Lighttpd with mod_fastcgi:
$client = new Client('unix:/var/run/php/php7.4-fpm.sock', -1);
$content = 'key=value';
echo $client->request(
    array(
        'GATEWAY_INTERFACE' => 'FastCGI/1.0',
        'REQUEST_METHOD' => 'POST',
        'SCRIPT_FILENAME' => '/usr/local/nginx/html/info.php',
        'SERVER_SOFTWARE' => 'php/fcgiclient',
        'REMOTE_ADDR' => '127.0.0.1',
        'REMOTE_PORT' => '9985',
        'SERVER_ADDR' => '127.0.0.1',
        'SERVER_PORT' => '80',
        'SERVER_NAME' => 'mag-tured',
        'SERVER_PROTOCOL' => 'HTTP/1.1',
        'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
        'CONTENT_LENGTH' => strlen($content)
    ),
    $content
);
CatAnonymous commented 4 years ago

Can u convert fsockopen to cURL?

adoy commented 4 years ago

I'm not sure what you mean by replacing fsockopen by cURL ? Your script is trying to connect via TCP instead of using a unix socket. You should use 'unix:///var/run/php/php7.4-fpm.sock' and not 'unix:/var/run/php/php7.4-fpm.sock'

CatAnonymous commented 4 years ago

I'm not sure what you mean by replacing fsockopen by cURL ? Your script is trying to connect via TCP instead of using a unix socket. You should use 'unix:///var/run/php/php7.4-fpm.sock' and not 'unix:/var/run/php/php7.4-fpm.sock'

It works, thanks the author

CatAnonymous commented 4 years ago

I'm not sure what you mean by replacing fsockopen by cURL ? Your script is trying to connect via TCP instead of using a unix socket. You should use 'unix:///var/run/php/php7.4-fpm.sock' and not 'unix:/var/run/php/php7.4-fpm.sock'

Can I separate body and headers?

CatAnonymous commented 4 years ago

I see a similar and this is how they Parse header body and error

https://raw.githubusercontent.com/hollodotme/fast-cgi-client/master/src/Responses/Response.php

adoy commented 4 years ago

You have to do it on your own. The current state of the lib is not doing it.

CatAnonymous commented 4 years ago

You have to do it on your own. The current state of the lib is not doing it.

I see self::STDERR content (type=7) Can you detach it from the response? The best thing is that you can do it directly into this lib

array(
  'states' => 0,
  'response' => '',
  'error' => ''
)

It is a php FPM error message, not a response content