- Can I use phpClickHouse with Laravel’s Eloquent ORM for ClickHouse data?
- phpClickHouse isn’t designed for direct Eloquent integration, but you can use custom accessors/mutators to handle ClickHouse-specific types like DateTime64 or UUID. For complex queries, consider a repository pattern or Laravel’s Query Builder with the package’s native parameter bindings.
- How do I configure phpClickHouse as a secondary database connection in Laravel?
- Add a `clickhouse` connection in `config/database.php` with the package’s client configuration. Use `DB::connection('clickhouse')` to run queries. Example: `$results = DB::connection('clickhouse')->select('SELECT * FROM analytics');`
- Does phpClickHouse support async queries in Laravel?
- Yes, phpClickHouse supports async queries natively. For Laravel, offload async operations to Laravel Queues (e.g., `bus:work`) or use ReactPHP for event-driven async workflows. Bulk inserts can also be queued for background processing.
- What Laravel versions and PHP versions does phpClickHouse support?
- phpClickHouse requires PHP 8.1+. It’s framework-agnostic but works seamlessly with Laravel 9+ (or 8 with minor adjustments). Ensure your Laravel app meets the PHP 8.1+ requirement for full compatibility.
- How do I handle ClickHouse’s DateTime64 type in Laravel models?
- Use Eloquent accessors/mutators to convert DateTime64 to Carbon instances. For example, add `getDateTime64Attribute()` to your model to format ClickHouse timestamps. Alternatively, use custom casts in Laravel 8+.
- Can I use phpClickHouse for real-time analytics dashboards in Laravel?
- Absolutely. phpClickHouse’s native parameter bindings and async query support make it ideal for real-time dashboards. Cache frequent queries in Redis and use Laravel’s Query Builder macros to extend ClickHouse-specific syntax.
- What are the alternatives to phpClickHouse for Laravel + ClickHouse?
- Alternatives include the official ClickHouse DBAL (PHP extension) for lower latency or Laravel-specific packages like `spatie/laravel-clickhouse`. However, phpClickHouse offers a more feature-rich, zero-dependency PHP client with advanced features like bulk inserts and cluster support.
- How do I perform bulk inserts from Laravel into ClickHouse using phpClickHouse?
- Use the `insert()` method with arrays or streams. Example: `$db->insert('events', $batchData, ['event_time', 'user_id'])` for structured inserts. For large datasets, stream data via generators or CSV files for memory efficiency.
- Does phpClickHouse support ClickHouse clusters with failover?
- Yes, phpClickHouse includes built-in cluster support with auto-discovery, health checks, and replica routing. Configure multiple hosts in the client options, and the package will handle failover automatically.
- How do I monitor query performance in Laravel when using phpClickHouse?
- Use Laravel’s built-in query logging or integrate with Prometheus via custom middleware. phpClickHouse provides structured exceptions with query IDs, which can be logged for debugging. For async queries, track job progress in Laravel Horizon.