napoler / solr-php-client

Automatically exported from code.google.com/p/solr-php-client
Other
0 stars 0 forks source link

incorrect implementation of "ping" #89

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
method "Apache\Solr\Service::ping" tries to request "/admin/ping" via method 
HEAD. But HEAD requests shouldn't return a response body (ref: 
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4). Method and 
called methods expects a parsable response body. So even solr instance is up, 
because of "empty response body" instance considered as down.

Platform: Centos 6.2
Container: Tomcat 6
Solr version: 4.0

Original issue reported on code.google.com by anilce...@gmail.com on 16 Jan 2013 at 8:07

GoogleCodeExporter commented 9 years ago
Correct, they won't return a response BODY, however, they do return an HTTP 
status and additional headers, which is what it cares about. ping excerpt:

$httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout);
$solrResponse = new Apache_Solr_Response($httpResponse, 
$this->_createDocuments, $this->_collapseSingleValueArrays);

if ($solrResponse->getHttpStatus() == 200)
{
    return microtime(true) - $start;
}
else
{
    return false;
}

Have you tried directly getting the admin ping handler for your solr instance? 
perhaps your configuration doesn't have it enabled and that's why a ping is 
failing. It relies on the admin/ping handler being configured.

Original comment by donovan....@gmail.com on 16 Jan 2013 at 3:59

GoogleCodeExporter commented 9 years ago
thanks for your fast also kind answer. whenever i switch to the  
"performGetRequest" ping works flawlessly. is there any kind of setting about 
admin/ping to accept HEAD?

Original comment by anilce...@gmail.com on 16 Jan 2013 at 9:53

GoogleCodeExporter commented 9 years ago
interesting. Which of the HTTP transports are you using?

I'll probably double check all of them on my side, but it'll be good to know.

While I'm asking, can you give me the PHP version, just in case.

Original comment by donovan....@gmail.com on 16 Jan 2013 at 10:38

GoogleCodeExporter commented 9 years ago
transport class is the one which uses "file_get_contents" method. it returns 
empty body (not false) but does not fills variable $http_response_header. php 
version is 5.4.9 i take a look at php changelog also bug reports about this 
method but no luck.

if nobody faced this before i have to suspect my platform. i will dig deeper 
with stack trace tomorrow.

Original comment by anilce...@gmail.com on 17 Jan 2013 at 6:39

GoogleCodeExporter commented 9 years ago
I have unit tests that cover the head requests for each transport in the tests 
directory of the full checkout. If possible, can you try running them? simplest 
way is from the checkout root to do: php tests/run.php

you will need phpunit installed, you can find pecl and compose install 
instructions on the site: https://github.com/sebastianbergmann/phpunit/  Note: 
I personally run phpunit  3.6.11 at the moment. 

If you can't run the phpunit, because of the version or trouble installing, I'd 
also be interested in you running this test script (expects the Apache 
directory of the client to be on the include path):

<?php

require_once('Apache/Solr/HttpTransport/Interface.php');
require_once('Apache/Solr/HttpTransport/Response.php');
require_once('Apache/Solr/HttpTransport/Abstract.php');
require_once('Apache/Solr/HttpTransport/Curl.php');
require_once('Apache/Solr/HttpTransport/CurlNoReuse.php');
require_once('Apache/Solr/HttpTransport/FileGetContents.php');

$implementations = array(
        'Apache_Solr_HttpTransport_Curl',
        'Apache_Solr_HttpTransport_CurlNoReuse',
        'Apache_Solr_HttpTransport_FileGetContents'
);

foreach ($implementations as $implementation) {
        $instance = new $implementation();
        $response = $instance->performHeadRequest("http://www.google.com");

        echo $implementation, "\n";
        print_r($response);
        echo "\n\n";
}

?>

I got output that looked like this:

Apache_Solr_HttpTransport_Curl
Apache_Solr_HttpTransport_Response Object
(
    [_statusCode:Apache_Solr_HttpTransport_Response:private] => 200
    [_statusMessage:Apache_Solr_HttpTransport_Response:private] => OK
    [_mimeType:Apache_Solr_HttpTransport_Response:private] => text/html
    [_encoding:Apache_Solr_HttpTransport_Response:private] => ISO-8859-1
    [_responseBody:Apache_Solr_HttpTransport_Response:private] =>
)

Apache_Solr_HttpTransport_CurlNoReuse
Apache_Solr_HttpTransport_Response Object
(
    [_statusCode:Apache_Solr_HttpTransport_Response:private] => 200
    [_statusMessage:Apache_Solr_HttpTransport_Response:private] => OK
    [_mimeType:Apache_Solr_HttpTransport_Response:private] => text/html
    [_encoding:Apache_Solr_HttpTransport_Response:private] => ISO-8859-1
    [_responseBody:Apache_Solr_HttpTransport_Response:private] =>
)

Apache_Solr_HttpTransport_FileGetContents
Apache_Solr_HttpTransport_Response Object
(
    [_statusCode:Apache_Solr_HttpTransport_Response:private] => 200
    [_statusMessage:Apache_Solr_HttpTransport_Response:private] => OK
    [_mimeType:Apache_Solr_HttpTransport_Response:private] => text/html
    [_encoding:Apache_Solr_HttpTransport_Response:private] => ISO-8859-1
    [_responseBody:Apache_Solr_HttpTransport_Response:private] =>
)

what'd you get?

Original comment by donovan....@gmail.com on 17 Jan 2013 at 9:19

GoogleCodeExporter commented 9 years ago
Apache_Solr_HttpTransport_Curl
Apache_Solr_HttpTransport_Response Object
(
    [_statusCode:Apache_Solr_HttpTransport_Response:private] => 302
    [_statusMessage:Apache_Solr_HttpTransport_Response:private] => Found
    [_mimeType:Apache_Solr_HttpTransport_Response:private] => text/html
    [_encoding:Apache_Solr_HttpTransport_Response:private] => UTF-8
    [_responseBody:Apache_Solr_HttpTransport_Response:private] => 
)

Apache_Solr_HttpTransport_CurlNoReuse
Apache_Solr_HttpTransport_Response Object
(
    [_statusCode:Apache_Solr_HttpTransport_Response:private] => 302
    [_statusMessage:Apache_Solr_HttpTransport_Response:private] => Found
    [_mimeType:Apache_Solr_HttpTransport_Response:private] => text/html
    [_encoding:Apache_Solr_HttpTransport_Response:private] => UTF-8
    [_responseBody:Apache_Solr_HttpTransport_Response:private] => 
)

Apache_Solr_HttpTransport_FileGetContents
Apache_Solr_HttpTransport_Response Object
(
    [_statusCode:Apache_Solr_HttpTransport_Response:private] => 0
    [_statusMessage:Apache_Solr_HttpTransport_Response:private] => Communication Error
    [_mimeType:Apache_Solr_HttpTransport_Response:private] => text/plain
    [_encoding:Apache_Solr_HttpTransport_Response:private] => UTF-8
    [_responseBody:Apache_Solr_HttpTransport_Response:private] => 
)

Original comment by anilce...@gmail.com on 18 Jan 2013 at 8:36

GoogleCodeExporter commented 9 years ago
Also nothing from stack trace;

request:
HEAD /ew/admin/ping HTTP/1.1\r\nUser-Agent: PHP/5.4.9\r\nHost: 
10.231.14.250:8080\r\nAccept: */*\r\n\r\n

response:
HTTP/1.1 200 OK\r\nServer: Apache-Coyote/1.1\r\nContent-Type: 
application/xml;charset=UTF-8\r\nContent-Length: 0\r\nDate: Fri, 18 Jan 2013 
08:38:45 GMT\r\n\r\n

Original comment by anilce...@gmail.com on 18 Jan 2013 at 8:47

GoogleCodeExporter commented 9 years ago
interestingly when I call"get_headers($url)"  in the method 
"Apache_Solr_HttpTransport_FileGetContents::performHeadRequest", it populates 
the headers plus it fills up the "$http_response_header" auto-magically :D. I 
think this bug is for PHP.

Original comment by anilce...@gmail.com on 18 Jan 2013 at 8:57

GoogleCodeExporter commented 9 years ago
https://bugs.php.net/bug.php?id=64016

Original comment by anilce...@gmail.com on 18 Jan 2013 at 11:20

GoogleCodeExporter commented 9 years ago
another thing to quickly check, 
http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Original comment by donovan....@gmail.com on 18 Jan 2013 at 3:49