elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
5.27k stars 965 forks source link

will elasticsearch-php pre-open the urls on the page when I visit it? #1410

Closed chongshengdz closed 1 month ago

chongshengdz commented 3 months ago

I wrote an extension using elasticsearch-php to search my seo urls for my website. but when I turn on the extension, the port 80 goes up rapidly. when i turn off the extension, everything goes normal. will elasticsearch-php pre-open the urls on the page when I visit it?

chongshengdz commented 2 months ago

website port 80 being flooded by thousands of connections when I turn on elasticsearch-php here is the code, please help check if anything wrong? @ezimuel

public function rewrite(string $link): string {
    $url_info = parse_url(str_replace('&', '&', $link));

    // Build the url
    $url = '';

    if ($url_info['scheme']) {
        $url .= $url_info['scheme'];
    }

    $url .= '://';

    if ($url_info['host']) {
        $url .= $url_info['host'];
    }

    if (isset($url_info['port'])) {
        $url .= ':' . $url_info['port'];
    }

    parse_str($url_info['query'], $query);

    // Start changing the URL query into a path
    $paths = [];

    // Parse the query into its separate parts
    $parts = explode('&', $url_info['query']);

    foreach ($parts as $part) {
        $pair = explode('=', $part);

        if (isset($pair[0])) {
            $key = (string)$pair[0];
        }

        if (isset($pair[1])) {
            $value = (string)$pair[1];
        } else {
            $value = '';
        }

$keyvalue = $key.'='.$value; $filter_data = [ 'filter_keyvalue' => (string)$keyvalue, 'limit' => 1 ];

    if ($this->config->get('module_search_plus_status')) {
    $this->load->model('extension/elasticsearch/module/search_plus_seourl');
    $params = $this->request->get;
    $searchParams = $this->model_extension_elasticsearch_module_search_plus_seourl->processParams($filter_data);
    $results = $this->model_extension_elasticsearch_module_search_plus_seourl->findProducts($searchParams);

    } else {
        $result = $this->model_design_seo_url->getSeoUrlByKeyValue((string)$key, (string)$value);
    }

foreach ($results['products'] as $result) {

        if ($result) {
            $paths[] = $result;
            unset($query[$key]);
        }
    }

} $sort_order = [];

    foreach ($paths as $key => $value) {
        $sort_order[$key] = $value['sort_order'];
    }

    array_multisort($sort_order, SORT_ASC, $paths);

    // Build the path
    $url .= str_replace('/index.php', '', $url_info['path']);

    foreach ($paths as $result) {
        $url .= '/' . $result['keyword'];
    }

    // Rebuild the URL query
    if ($query) {
        $url .= '?' . str_replace(['%2F'], ['/'], http_build_query($query));
    }

    return $url;
}
chongshengdz commented 2 months ago

When I turn on elasticsearch, it produces hundreds thousands of TIME_WAIT connections

tcp6 0 0 ::1:58056 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:46180 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:46380 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:36806 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:58086 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:46880 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:44800 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:48880 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:43580 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:47980 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:38380 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:35180 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:39580 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:49180 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:34480 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:53807 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:53880 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:46480 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:38092 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:59280 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:58808 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:58070 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:58018 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:39806 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:52809 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:54804 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:53802 ::1:9200 TIME_WAIT - tcp6 0 0 ::1:52280 ::1:9200 TIME_WAIT -

ezimuel commented 2 months ago

@chongshengdz the elasticsearch-php uses port 9200 by default for connecting to Elasticsearch but only when an endpoint is executed, e.g. $client->info().

Which version of elastic/elasticsearch-php and PHP are you using? Can you show me the initialization code of the Elastic\Elasticsearch\Client? Are you using the ClientBuilder?

Let me know, thanks.