定制 iwai/elasticsearch-guzzle5connection 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

iwai/elasticsearch-guzzle5connection

最新稳定版本:1.0.1

Composer 安装命令:

composer require iwai/elasticsearch-guzzle5connection

包简介

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

Async support for elasticsearch-php

Caution!!!

  • Unsupported ping method
  • Unsupported exists method
  • Unsupported logging

Install

{
    "require": {
        "elasticsearch/elasticsearch": "~1.0",
        "iwai/elasticsearch-guzzle5connection": "~1.0"
    }
}

Example

Transparent async request

use Elasticsearch\Client as ESClient;

$client = new ESClient([
    'hosts' => [ '127.0.0.1:9200' ],
    'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection',
    'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer'
]);

$response = $client->get([
    'index' => 'index_name',
    'type'  => 'type',
    'id'    => '1',
]);

echo $response['hits']['total'];

Explicit wait request

use Elasticsearch\Client as ESClient;

$client = new ESClient([
    'hosts' => [ '127.0.0.1:9200' ],
    'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection',
    'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer'
]);

$future = $client->get([
    'index' => 'index_name',
    'type'  => 'type',
    'id'    => '1',
]);

$response = $future->wait();

echo $response['hits']['total'];

Promise style

use Elasticsearch\Client as ESClient;

$client = new ESClient([
    'hosts' => [ '127.0.0.1:9200' ],
    'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection',
    'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer'
]);

$future = $client->get([
    'index' => 'index_name',
    'type'  => 'type',
    'id'    => '1',
]);

$futureData->then(function ($response) {
    echo $response['hits']['total'];
});

With RingPHP

use React\EventLoop;
use WyriHaximus\React\RingPHP\HttpClientAdapter;
use Elasticsearch\Client as ESClient;

$loop  = EventLoop\Factory::create();

$client = new ESClient([
    'hosts' => [ '127.0.0.1:9200' ],
    'connectionClass' => '\Iwai\Elasticsearch\Guzzle5Connection', // required
    'serializerClass' => '\Iwai\Elasticsearch\FutureSerializer',  // required
    'connectionParams' => [ 'ringphp_handler' => new HttpClientAdapter($loop) ] // optional
]);

$futureData = $client->get([
    'index' => 'index_name',
    'type'  => 'type',
    'id'    => '1',
]);

$futureData->then(function ($response) {
    echo $response['hits']['total'];
});

$loop->run();

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-12-20