typesense/typesense-php
Official PHP client for the Typesense search API. Install via Composer and use any HTTPlug-compatible HTTP client. Provides helpers like safe filter_by string escaping and supports modern Typesense server versions.
typesense/typesense-php package is a highly specialized client for Typesense, a real-time search and analytics engine. It aligns perfectly with Laravel applications requiring scalable, typo-tolerant, and faceted search (e.g., e-commerce, content platforms, or analytics dashboards).Guzzle, Symfony HTTP Client) or custom adapters. This reduces vendor lock-in.composer require typesense/typesense-php + an HTTP client (e.g., php-http/curl-client). No Laravel-specific setup is needed beyond configuration..env for API keys, host, port).| Risk Area | Mitigation Strategy |
|---|---|
| Version Mismatch | Strict compatibility matrix (e.g., v6.x for Typesense ≥30.0). Use composer constraints to lock versions. |
| HTTP Client Dependencies | Requires HTTPlug-compatible client (e.g., Guzzle). Laravel’s Http facade can wrap this. |
| Breaking Changes | v5.0.0+ enforces URL encoding for resource names (e.g., collection IDs). Audit existing code for manual encoding. |
| Performance Overhead | Retry logic and HTTP abstraction add ~5–10ms latency. Benchmark under load. |
| Error Handling | Custom exceptions (e.g., Typesense\Exceptions\TypesenseException) need wrapping for Laravel’s App\Exceptions\Handler. |
| Streaming Responses | Supports streamed responses (e.g., for large exports), but Laravel’s Blade/JSON responses may need buffering. |
multiSearch.SearchService) for consistency?/health and /operations endpoints)?Http facade or Guzzle directly. Example:
$client = new Typesense\Client([
'nodes' => ['localhost:8108'],
'connection_timeout_seconds' => 2,
'http_client' => new \Http\Adapter\Guzzle7Client(),
]);
AppServiceProvider:
$this->app->singleton(Typesense\Client::class, fn($app) => new Typesense\Client(config('typesense')));
Search::query()->filter(...))./schema endpoint to mirror Laravel models (e.g., via migrations).created, updated).$client->collections()->documents('products')->import([...]);
| Component | Compatibility Notes |
|---|---|
| Laravel Versions | Tested with Laravel 10 (v4.8.2+). Backward-compatible with older versions. |
| PHP Versions | Requires PHP 8.0+. Laravel 10+ aligns with this. |
| Typesense Server | Version matrix ensures compatibility (e.g., v6.x for Typesense ≥30.0). |
| Existing Search Logic | Minimal refactoring needed if using raw API calls. Replace with client methods. |
| Third-Party Packages | No conflicts with Laravel’s ecosystem (e.g., Scout, Echo). |
search($query, $filters)).ping endpoint to query Typesense /health).composer normalize to manage version constraints.$client = new Typesense\Client([
'nodes' => [...],
'logger' => new Typesense\Logger\MonologLogger($this->app->make(\Monolog\Logger::class)),
]);
Handler for consistent error responses:
catch (Typesense\Exceptions\TypesenseException $e) {
return response()->json(['error' => 'Search failed'], 500);
}
How can I help you explore Laravel packages today?