flyokai/amp-opensearch 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

flyokai/amp-opensearch

最新稳定版本:0.1.0

Composer 安装命令:

composer require flyokai/amp-opensearch

包简介

opensearch client connection handler backed with amphp/http-client

README 文档

README

User docs → README.md · Agent quick-ref → CLAUDE.md · Agent deep dive → AGENTS.md

Async OpenSearch client for PHP — bridges the official opensearch-project/opensearch-php SDK with AMPHP's non-blocking HTTP client.

Drops in as a custom request handler so you can keep using the official SDK API while every call is non-blocking under Revolt.

Features

  • AmpHandler — callable handler for OpenSearch\ClientBuilder::setHandler()
  • HttpClientBuilder — configured AMPHP HttpClient with connection pooling
  • Configurable retry (limit + delay)
  • Returns Guzzle\CompletedFutureArray (the format the SDK expects)

Installation

composer require flyokai/amp-opensearch

Quick start

use Flyokai\AmpOpensearch\AmpHandler;
use Flyokai\AmpOpensearch\HttpClientBuilder;
use OpenSearch\ClientBuilder;

$handler = new AmpHandler(
    (new HttpClientBuilder())->build(),
    retryLimit: 3,
    retryDelay: 0.1,
);

$client = (new ClientBuilder())
    ->setHandler($handler)
    ->setHosts(['https://localhost:9200'])
    ->setBasicAuthentication('admin', 'admin')
    ->setSSLVerification(false)
    ->build();

$client->index([
    'index' => 'products',
    'id'    => 1,
    'body'  => ['name' => 'Foo', 'price' => 9.99],
]);

$result = $client->search([
    'index' => 'products',
    'body'  => ['query' => ['match' => ['name' => 'Foo']]],
]);

Every call inside fibers is fully non-blocking — the SDK doesn't know.

Architecture

AmpHandler::__invoke(array $request) is invoked by the OpenSearch SDK for every operation. It:

  1. Translates the SDK request array into an AMPHP Request
  2. Executes via the configured HttpClient
  3. Wraps the response as CompletedFutureArray with: status, reason, headers, body (php://memory), effective_url, transfer_stats, error
  4. Retries up to retryLimit times with retryDelay between attempts on failure

HttpClientBuilder::build() returns an AMPHP HttpClient with:

  • TLS without peer verification (development default)
  • UnlimitedConnectionPool
  • DefaultConnectionFactory + ConnectContext

Gotchas

  • SSL verification disabled by default. HttpClientBuilder calls withoutPeerVerification(). Review for production.
  • Hard-coded JSON headers. Content-Type and Accept are always application/json. Not customizable per request.
  • Memory stream for responsesphp://memory. No streaming.
  • transfer_stats is incompletetotal_time is hardcoded to 0.
  • Requires Revolt event loop context — retry delays use EventLoop::delay() + suspension. Will fail outside fibers.

See also

License

MIT

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固