Weave 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

Phpclickhouse Laravel Package

smi2/phpclickhouse

PHP client for ClickHouse with sync and async queries, native parameter binding, bulk inserts, generators, gzip compression, cluster support, streaming, and progress callbacks. Requires PHP 8.1+, ext-curl, ext-json.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • High Fit for Laravel analytics workloads: The package remains a zero-dependency PHP ClickHouse client, suitable for Laravel applications needing OLAP, real-time analytics, time-series data, event sourcing, CQRS, or dashboarding.
  • Laravel Integration: Still integrates through a Service Provider / facade, Query Builder macros, and custom Eloquent casts/accessors; it is not a native Eloquent driver, so ClickHouse DDL and advanced types require application-level handling.
  • Hybrid Architecture: Best positioned as a secondary analytical store alongside PostgreSQL/MySQL rather than a transactional replacement.
  • Release 1.26.925 strengthens type safety: New string/date/enum wrappers, full numeric scalar types, and structured exceptions reduce several integration risks, especially around untrusted input and diagnostics.

Integration Feasibility

  • Laravel Service Provider / Facade: Still feasible via package registration and a ClickHouse facade over the client.
  • Typed value objects: New StringType, FixedString(N), Date, DateTime, Enum8, Enum16, Int8–Int256, UInt8–UInt256, Float32/64, and Decimal32–Decimal256 can be used at the application boundary before passing values into queries.
  • Security improvement: StringableType values are escaped by ValueFormatter, bindings, and native parameters; numeric fromString() validation closes an SQL-injection vector for untrusted input when these wrappers are adopted.
  • Structured exceptions: DatabaseException::getServerVersion() and getServerStackTrace() improve production diagnostics, but the server stack trace is not included in getMessage() and requires per-query ['stacktrace' => 1].
  • Eloquent fit remains partial: Custom casts/accessors are still needed for ClickHouse DateTime64, UUID, decimals, and enum types.

Technical Risk

Risk Area Assessment Mitigation Strategy
PHP runtime breaking change 1.26.925 requires PHP ^8.1; PHP 8.0 users must pin 1.26.4. Confirm all app/CI/container runtimes are PHP 8.1+ before upgrade; align with Laravel 10+ / Laravel 9 on PHP 8.1+.
Type Mismatch Laravel/Eloquent expects Carbon and native PHP scalars; ClickHouse uses DateTime64, Decimal, Enum, etc. Use custom casts/accessors and the new type wrappers at query boundaries.
Legacy Type escaping Release notes indicate legacy Type values are still interpolated into SQL unescaped; new wrappers are the safe path. Audit existing raw Type usage; migrate untrusted inputs to StringableType / ScalarNumericType wrappers.
Decimal precision json_decode() precision trap applies for >16-digit decimals; exact reads need toString(). Identify financial/high-precision columns; read as strings where exactness matters.
Connection Pooling No built-in Laravel connection pooling for ClickHouse. Use PHP-CLI workers, queue-based writes, and Redis/cache for hot reads where appropriate.
Async Query Handling Laravel’s synchronous request model may block on slow ClickHouse queries. Offload heavy inserts/queries to Laravel Queues; set per-query timeouts such as max_execution_time.
Schema Migrations ClickHouse DDL differs from Laravel migrations. Use custom Artisan commands or explicit schema-management scripts.
Error Handling Improved, but server stack traces require opt-in and explicit getter use. Log getServerVersion() / getServerStackTrace(); avoid enabling stack traces globally unless needed.
Performance Overhead HTTP client may add latency versus native drivers. Benchmark against expected QPS; cache frequent analytics responses.

Key Questions for TPM

  1. Runtime baseline: Are all Laravel apps, CI runners, and production containers on PHP 8.1+? If not, which services must pin 1.26.4?
  2. Security exposure: Are any user-supplied values currently passed through legacy Type objects rather than the new validated/escaped wrappers?
  3. Precision requirements: Do any analytics use cases require exact decimals beyond 16 digits, requiring string-based reads instead of JSON numeric decoding?
  4. Observability: Will the team capture getServerVersion() and getServerStackTrace() in logs? Will per-query stacktrace be enabled selectively?
  5. ClickHouse version: Production is on which ClickHouse version? The package now tests against CH 21.9 / 26.3 / 26.9, but the deployed version still needs validation.
  6. Use case: Is ClickHouse read-only analytics, write-heavy event ingestion, or hybrid? This determines queueing, batching, and caching design.

Integration Approach

Stack Fit

Laravel Component Integration Strategy
Database Layer Register ClickHouse as a secondary connection in config/database.php.
Query Builder Extend with macros for ClickHouse-specific syntax and native parameters.
Eloquent Use custom casts/accessors for DateTime64, Decimal, Enum, and UUID; consider repositories for complex analytical queries.
Migrations Use custom Artisan commands or schema scripts; do not assume Laravel migrations cover ClickHouse DDL.
Queues/Jobs Offload bulk inserts and slow analytical queries to Laravel Queues.
API Layer Use ClickHouse for analytics endpoints such as /metrics and /reports; cache frequent responses.
Caching Cache high-cost ClickHouse reads in Redis or Laravel Cache.
Validation / Formatting Adopt new type wrappers for untrusted strings, numerics, dates, and enums before query execution.

Migration Path

  1. Phase 0: Runtime and security compatibility
    • Confirm PHP 8.1+ across Laravel apps and CI.
    • Pin 1.26.4 only for services still on PHP 8.0.
    • Audit existing Type usage and identify untrusted inputs that should move to StringableType / ScalarNumericType.
  2. Phase 1: Read-only analytics
    • Introduce ClickHouse as a secondary connection.
    • Move PostgreSQL-heavy reporting queries to ClickHouse.
    • Use DB::connection('clickhouse') or a facade for read queries.
  3. Phase 2: Write support with safe typing
    • Implement bulk inserts via queued jobs.
    • Use new string/numeric/date/enum wrappers at ingestion boundaries.
    • Handle decimal reads carefully; use toString() where precision matters.
  4. Phase 3: Hybrid transactions
    • Keep PostgreSQL/MySQL as the transactional source of truth.
    • Dispatch async ClickHouse sync jobs after application events or transactions.
  5. Phase 4: Expand analytical ownership
    • Migrate read-heavy analytical tables where appropriate.
    • Keep transactional workloads out of ClickHouse unless explicitly validated.

Compatibility

Laravel / PHP Feature Compatibility Notes
PHP 8.1+ Required by 1.26.925; PHP 8.0 users must pin older release.
Laravel 10+ Strong fit on PHP 8.1+; package remains framework-agnostic but integrable.
Laravel 9 Feasible where runtime is PHP 8.1+, but validate package CI coverage and app dependencies.
Eloquent Models Works via custom casts/accessors, not as a full native Eloquent driver.
Migrations Requires custom Artisan commands or external schema management.
Query Builder Extendable via macros; use native parameters where possible.
Queues Use Laravel Queues for async inserts and slow analytical queries.
Caching Cache ClickHouse results in Redis/Laravel Cache for hot analytics.
Observability Structured exceptions improve diagnostics; server stack traces require opt-in per query.

Sequencing

  1. Upgrade dependency and runtime
    • Set Composer constraint appropriately.
    • Ensure CI covers PHP 8.1–8.4 and the production ClickHouse version.
  2. Register ClickHouse connection and facade
    • Add secondary connection config.
    • Register package service provider and optional facade.
  3. Add safe type usage
    • Use new string/numeric/date/enum wrappers for untrusted values.
    • Replace raw legacy Type interpolation where possible.
  4. Implement async writes
    • Create queued jobs for bulk inserts.
    • Add retry/backoff and idempotency handling.
  5. Add observability
    • Log getServerVersion() and getServerStackTrace().
    • Enable per-query stack traces selectively.
    • Add query timing and failure metrics.
  6. Validate precision and ClickHouse version
    • Test decimal-heavy queries against production ClickHouse.
    • Confirm JSON decoding behavior for high-precision decimals.

Operational Impact

Maintenance

Task Effort Level Notes
Dependency Updates Medium PHP 8.1 is now the floor; monitor compatibility with Laravel and PHP 8.2–8.4.
Schema Changes High ClickHouse lacks native Laravel migrations; maintain explicit DDL scripts.
Type Wrapper Adoption Medium New wrappers improve safety but require auditing existing Type usage.
Exception Handling Low–Medium Structured exceptions improve support; ensure logs include server version/stack trace getters.
ClickHouse Version Testing Medium Package tests CH 21.9 / 26.3 / 26.9; production version must be in CI or staging.

Support

  • Improved diagnostics: Structured exceptions provide server version and optional server stack trace.
  • Support caveat: Server stack traces are not in the exception message; support runbooks must explicitly log/read them.
  • Runtime caveat: PHP 8.0 services will fail Composer resolution on 1.26.925 and must pin 1.26.4.
  • Type safety caveat: Security benefit depends on adopting new wrappers; legacy unescaped Type usage remains a risk.

Scaling

  • Read scaling: Use Redis/cache for repeat analytics queries; keep ClickHouse queries bounded with timeouts.
  • Write scaling: Prefer queued bulk inserts over synchronous per-request writes.
  • Connection management: The client does not provide Laravel-native pooling; plan worker-based or queue-based access patterns.
  • Precision scaling: For high-precision decimals, read as strings to avoid JSON decoding precision loss.

Failure Modes

Failure Mode Impact Mitigation
PHP version mismatch Composer install/upgrade failure Enforce PHP 8.1+ in CI/containers; pin 1.26.4 where needed.
Legacy Type injection risk SQL injection if untrusted values are interpolated Migrate to StringableType / ScalarNumericType wrappers.
Decimal precision loss Incorrect financial/high-precision analytics Use toString() for exact decimal reads.
Slow analytical query Request latency or timeout Queue heavy queries; set max_execution_time; cache results.
ClickHouse schema drift Query failures after deployment Use explicit DDL scripts and staged schema validation.
Missing server stack trace Slower production debugging Enable per-query stacktrace where needed and log getServerStackTrace().
ClickHouse version mismatch Untested SQL/type behavior Run CI/staging against the production ClickHouse version.

Ramp-Up

  • TPM / engineering effort: Medium.
  • Team learning needs: ClickHouse type system, decimal precision behavior, async ingestion patterns, and structured exception handling.
  • Recommended first milestone: Upgrade runtime compatibility, adopt safe type wrappers for untrusted inputs, and add structured exception logging before expanding ClickHouse usage.
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.
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package