bavix/clickhouse-php-client
PHP 7.1+ ClickHouse HTTP client built on Guzzle. Supports single server or clusters, server selection by name/tags, and running queries per cluster. Provides async SELECT and INSERT from local files for efficient ingestion and querying.
bavix/clickhouse-php-client package provides a low-level HTTP-based client for ClickHouse, making it suitable for applications requiring direct SQL query execution or real-time analytics via ClickHouse’s HTTP interface. It aligns well with:
clickhouse-driver) are unavailable.clickhouse-driver or clickhouse-php).ServiceProvider for dependency injection.ClickHouse::table('events')->select(...)).config/database.php (though this would require custom logic).| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| Latency | HTTP overhead may degrade performance for high-frequency queries. | Benchmark against native drivers; use connection pooling (e.g., Guzzle HTTP client). |
| Error Handling | ClickHouse-specific errors (e.g., Code: 400) require custom parsing. |
Implement a uniform exception class (e.g., ClickHouseException). |
| Schema Migrations | No built-in migration support → Manual SQL or Doctrine Migrations integration needed. | Use Laravel’s Schema builder for relational DBs; raw SQL for ClickHouse. |
| Dependency Stability | Low-star package with no recent activity (last release in 2026). | Fork or contribute; monitor for updates; consider alternatives (e.g., clickhouse-driver). |
| Laravel ORM Gaps | Eloquent models won’t work out-of-the-box with ClickHouse’s schema (e.g., nested data). | Use custom accessors/mutators or a hybrid model (e.g., ClickHouseModel). |
Array, Map)? If yes, how will Laravel models handle serialization?clickhouse-driver or clickhouse-php been evaluated? Why was this package chosen?Guzzle (recommended) or Symfony HTTP Client for connection pooling.DB facade (e.g., ClickHouse::query()).Accept-Encoding: gzip) for large result sets.curl).ClickHouse) to wrap raw HTTP calls:
// Example facade method
public function select(string $query, array $params = [])
{
$client = app(ClickHouseClient::class);
return $client->select($query, $params);
}
DB::listen) for debugging.config/database.php:
'connections' => [
'clickhouse' => [
'driver' => 'clickhouse-http',
'host' => env('CLICKHOUSE_HOST'),
'port' => env('CLICKHOUSE_PORT'),
'database' => env('CLICKHOUSE_DB'),
'username' => env('CLICKHOUSE_USER'),
'password' => env('CLICKHOUSE_PASSWORD'),
'options' => [
'http_client' => 'guzzle', // Custom HTTP client config
],
],
],
Connection class extending Laravel’s Connection to handle ClickHouse-specific logic.arrayJoin) without raw SQL.enable_http_compression is set if needed)..env with ClickHouse credentials.composer require bavix/clickhouse-php-client guzzlehttp/guzzle
tap or dump() to inspect HTTP responses:
$result = $client->select('SELECT * FROM events LIMIT 1')->tap(function ($response) {
Log::debug('Raw response:', $response->getBody());
});
log_queries = 1 in config.xml).8123) is open.users.xml.EXPLAIN to analyze query plans.Guzzle with a pool to reuse HTTP connections:How can I help you explore Laravel packages today?