ruflin / Elastica

Elastica is a PHP client for elasticsearch
http://elastica.io/
MIT License
2.26k stars 733 forks source link

Can't get elastic response when disabling proxy but works in command line #2192

Closed Shotman closed 4 months ago

Shotman commented 5 months ago

I have a server that must use a proxy per company policy When using curl in command line with : curl --noproxy '*' -X PUT -u usr:pass [IP]:9200/toto everything works as expected. But with the configuration on FOSElasticaBundle

curl:
                !php/const \CURLOPT_NOPROXY: true

I get a

  [Elastica\Exception\Connection\HttpException]
  Unknown error:56

Wich is

CURLE_RECV_ERROR (56)

Failure with receiving network data.

So why does it work with basic command line but not using the PHP HTTP client ?

Here is some documentation on the request and response :

      #_connection: Elastica\Connection^ {
        #_params: [
          "config" => [
            "url" => "x.x.x.x/",
            "curl" => [
              10177 => true
            ],
            "headers" => []
          ],
          "port" => 9200,
          "username" => "user",
          "password" => "pass",
          "auth_type" => "basic",
          "http_error_codes" => [
            400,
            403,
            404
          ],
          "ssl" => false,
          "logger" => "fos_elastica.logger",
          "compression" => false,
          "retryOnConflict" => 0,
          "persistent" => true,
          "enabled" => false
        ]
        #_rawParams: []
      }
    }
    #_response: Elastica\Response^ {
      #_queryTime: 0.00074100494384766
      #_responseString: ""
      #_transferInfo: [
        "url" => "HTTP://x.x.x.x/toto",
        "content_type" => null,
        "http_code" => 0,
        "header_size" => 0,
        "request_size" => 937,
        "filetime" => -1,
        "ssl_verify_result" => 0,
        "redirect_count" => 0,
        "total_time" => 0.00065,
        "namelookup_time" => 2.5E-5,
        "connect_time" => 0.000279,
        "pretransfer_time" => 0.000306,
        "size_upload" => 730.0,
        "size_download" => 0.0,
        "speed_download" => 0.0,
        "speed_upload" => 1123076.0,
        "download_content_length" => -1.0,
        "upload_content_length" => 730.0,
        "starttransfer_time" => 0.0,
        "redirect_time" => 0.0,
        "redirect_url" => "",
        "primary_ip" => "y.y.y.y",
        "certinfo" => [],
        "primary_port" => 80,
        "local_ip" => "x.x.x.x",
        "local_port" => 47644
      ]
      #_response: []
      #_status: 0
      #_jsonBigintConversion: false
    }
    #_error: 56
    trace: {
      ./vendor/ruflin/elastica/src/Transport/Http.php:186 { …}
      ./vendor/ruflin/elastica/src/Request.php:183 { …}
      ./vendor/ruflin/elastica/src/Client.php:545 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Elastica/Client.php:63 { …}
      ./vendor/ruflin/elastica/src/Client.php:580 { …}
      ./vendor/ruflin/elastica/src/Index.php:774 { …}
      ./vendor/ruflin/elastica/src/Index.php:510 { …}
      ./vendor/friendsofsymfony/elastica-bundle/src/Command/CreateCommand.php:77 { …}
      ./vendor/symfony/console/Command/Command.php:326 { …}
      ./vendor/symfony/console/Application.php:1096 { …}
      ./vendor/symfony/framework-bundle/Console/Application.php:126 { …}
      ./vendor/symfony/console/Application.php:324 { …}
      ./vendor/symfony/framework-bundle/Console/Application.php:80 { …}
      ./vendor/symfony/console/Application.php:175 { …}
      ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49 { …}
      ./vendor/autoload_runtime.php:29 { …}
      ./bin/console:11 {
        ›
        › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
        ›
        arguments: {
          "[project_path]/vendor/autoload_runtime.php"
        }
      }
    }
  },
ruflin commented 4 months ago

Can you share a bit more on the exact PHP code that you are executing? I wonder if the proxy might reject it because of size or a timeout?

Unfortunately have never used Elastica with a proxy in between.

Shotman commented 4 months ago

I managed to make it work with a proxy, nothing to do with elastica or FOSElastica themselves just kind of a stange curl config requirement :

            curl:
                !php/const \CURLOPT_NOPROXY: ''
                !php/const \CURLOPT_PROXY: ''

Those 2 options ARE required to make Elastica ignore the proxy, the NO_PROXY one alone isn't enough, no idea why but it works now