flyokai / amp-opensearch
opensearch client connection handler backed with amphp/http-client
0.1.0
2026-04-29 15:47 UTC
Requires
- php: ^8.2
- amphp/http-client: ^5.1
- opensearch-project/opensearch-php: ^2.3
Requires (Dev)
- phpunit/phpunit: ^8.5
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-phpSDK 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 forOpenSearch\ClientBuilder::setHandler()HttpClientBuilder— configured AMPHPHttpClientwith 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:
- Translates the SDK request array into an AMPHP
Request - Executes via the configured
HttpClient - Wraps the response as
CompletedFutureArraywith:status,reason,headers,body(php://memory),effective_url,transfer_stats,error - Retries up to
retryLimittimes withretryDelaybetween attempts on failure
HttpClientBuilder::build() returns an AMPHP HttpClient with:
- TLS without peer verification (development default)
UnlimitedConnectionPoolDefaultConnectionFactory+ConnectContext
Gotchas
- SSL verification disabled by default.
HttpClientBuildercallswithoutPeerVerification(). Review for production. - Hard-coded JSON headers.
Content-TypeandAcceptare alwaysapplication/json. Not customizable per request. - Memory stream for responses —
php://memory. No streaming. transfer_statsis incomplete —total_timeis hardcoded to 0.- Requires Revolt event loop context — retry delays use
EventLoop::delay()+ suspension. Will fail outside fibers.
See also
flyokai/indexer— uses this for indexing operations.
License
MIT