Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Clickhouse Php Client Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The 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:
    • Event-driven architectures (e.g., streaming analytics, log aggregation).
    • Microservices needing lightweight, stateless ClickHouse interactions.
    • Serverless/edge computing where native drivers (e.g., clickhouse-driver) are unavailable.
  • Laravel Compatibility: Laravel’s Query Builder and Eloquent are not natively supported, requiring manual SQL execution or a custom abstraction layer. This may force a hybrid approach (e.g., using the package for raw queries while leveraging Laravel’s ORM for relational data).
  • Performance Considerations:
    • HTTP overhead may introduce latency compared to native drivers (e.g., clickhouse-driver or clickhouse-php).
    • Connection pooling must be managed manually (no built-in support).
    • Batch operations (e.g., bulk inserts) may require custom logic for efficiency.

Integration Feasibility

  • Laravel Ecosystem Fit:
    • Service Provider Integration: Can be bootstrapped via Laravel’s ServiceProvider for dependency injection.
    • Query Builder Wrapper: A custom facade or macro could abstract raw HTTP calls into a Laravel-like syntax (e.g., ClickHouse::table('events')->select(...)).
    • Database Connector: Could be registered as a secondary database connection in Laravel’s config/database.php (though this would require custom logic).
  • Authentication & Security:
    • Supports basic auth, tokens, and TLS (via HTTP headers), aligning with Laravel’s security practices.
    • No built-in query sanitizationSQL injection risk if raw user input is used. Must implement strict input validation or a prepared-statement-like layer.
  • Async Support:
    • No native async/await → May require Laravel Queues or ReactPHP for non-blocking operations.

Technical Risk

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).

Key Questions

  1. Performance Requirements:
    • Are low-latency queries critical? If so, is HTTP overhead acceptable, or should a native driver be prioritized?
  2. Schema Complexity:
    • Does the application rely on ClickHouse’s nested data types (e.g., Array, Map)? If yes, how will Laravel models handle serialization?
  3. Team Expertise:
    • Is the team comfortable maintaining a custom abstraction layer for ClickHouse queries?
  4. Alternatives:
    • Has clickhouse-driver or clickhouse-php been evaluated? Why was this package chosen?
  5. Future-Proofing:
    • Are there plans to migrate to a more actively maintained ClickHouse client (e.g., official Laravel package)?

Integration Approach

Stack Fit

  • Laravel Version: Tested with Laravel 10.x+ (PHP 8.1+). Ensure compatibility with:
    • HTTP Client: Guzzle (recommended) or Symfony HTTP Client for connection pooling.
    • Query Builder: Custom wrapper for Laravel’s DB facade (e.g., ClickHouse::query()).
    • Caching: Use Laravel’s cache (e.g., Redis) to store frequent query results.
  • ClickHouse Version:
    • Supports ClickHouse 22.3+ (HTTP interface). Verify compatibility with your cluster’s version.
    • Test compression (e.g., Accept-Encoding: gzip) for large result sets.

Migration Path

  1. Phase 1: Proof of Concept
    • Replace a single high-impact query (e.g., analytics dashboard) with the HTTP client.
    • Compare performance vs. existing solution (e.g., native driver or raw curl).
  2. Phase 2: Abstraction Layer
    • Build a Laravel facade (e.g., 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);
      }
      
    • Add query logging (via Laravel’s DB::listen) for debugging.
  3. Phase 3: Full Integration
    • Register as a database connection in 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
              ],
          ],
      ],
      
    • Create a custom Connection class extending Laravel’s Connection to handle ClickHouse-specific logic.

Compatibility

  • Laravel Features:
    • ✅ Supported: Raw SQL, prepared statements, transactions (if ClickHouse supports them).
    • ❌ Not Supported: Eloquent models (without custom logic), migrations (without raw SQL), relationships (nested data requires manual handling).
  • ClickHouse Features:
    • ✅ Supported: SQL queries, HTTP interface, authentication.
    • ❌ Limited: No native support for ClickHouse-specific functions (e.g., arrayJoin) without raw SQL.

Sequencing

  1. Infrastructure Setup:
    • Configure ClickHouse HTTP interface (ensure enable_http_compression is set if needed).
    • Set up Laravel’s .env with ClickHouse credentials.
  2. Dependency Installation:
    composer require bavix/clickhouse-php-client guzzlehttp/guzzle
    
  3. Development:
    • Start with read queries (simpler than writes).
    • Gradually introduce writes, batches, and async operations.
  4. Testing:
    • Unit tests for the abstraction layer.
    • Integration tests with real ClickHouse data.
    • Load tests for high-concurrency scenarios.

Operational Impact

Maintenance

  • Pros:
    • No native driver dependencies → Easier to deploy in restricted environments (e.g., Docker, serverless).
    • HTTP-based → Works behind proxies/firewalls with minimal config.
  • Cons:
    • Custom abstraction layer requires ongoing maintenance (e.g., updates to ClickHouse SQL syntax).
    • No official Laravel support → Bug fixes depend on community/contributor effort.
  • Recommendations:
    • Document query patterns and error codes for the team.
    • Set up monitoring for failed HTTP requests (e.g., ClickHouse server downtime).

Support

  • Debugging:
    • Use Laravel’s tap or dump() to inspect HTTP responses:
      $result = $client->select('SELECT * FROM events LIMIT 1')->tap(function ($response) {
          Log::debug('Raw response:', $response->getBody());
      });
      
    • Enable ClickHouse query logging (log_queries = 1 in config.xml).
  • Troubleshooting:
    • Connection Issues: Verify ClickHouse HTTP port (8123) is open.
    • Authentication: Ensure credentials match ClickHouse’s users.xml.
    • Performance: Use EXPLAIN to analyze query plans.

Scaling

  • Horizontal Scaling:
    • Connection Pooling: Use Guzzle with a pool to reuse HTTP connections:
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor