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

Phpclickhouse Laravel Package

smi2/phpclickhouse

PHP client for ClickHouse with an easy, fluent API. Supports queries and inserts, result sets, bindings, and connection configuration for fast analytics workflows. Suitable for Laravel and standalone PHP apps needing reliable ClickHouse access.

View on GitHub
Deep Wiki
Context7

layout: default title: Cluster

< Back to Home

Cluster

Setup

$config = [
    'host'     => 'cluster.clickhouse.dns.com', // any node name in cluster
    'port'     => '8123',
    'username' => 'default',                     // all nodes share login/password
    'password' => '',
];

// Client connects to first node by DNS, reads IP list, then connects to ALL nodes for health check
$cl = new ClickHouseDB\Cluster($config);
$cl->setScanTimeOut(2.5); // 2500 ms max per node

Health check

if (!$cl->isReplicasIsOk()) {
    throw new Exception('Replica state is bad, error=' . $cl->getError());
}

Node discovery

// All nodes and clusters
print_r($cl->getNodes());
print_r($cl->getClusterList());

// Nodes by cluster name
$name = 'some_cluster_name';
print_r($cl->getClusterNodes($name));

// Counts
echo "Count Shard   = " . $cl->getClusterCountShard($name) . "\n";
echo "Count Replica = " . $cl->getClusterCountReplica($name) . "\n";

Working with nodes

// Get nodes by table & print size per node
$nodes = $cl->getNodesByTable('shara.adpreview_body_views_sharded');
foreach ($nodes as $node) {
    echo "$node >\n";
    print_r($cl->client($node)->tableSize('adpreview_body_views_sharded'));
    print_r($cl->client($node)->showCreateTable('shara.adpreview_body_views'));
}

Select node by pattern

// Select by IP pattern, delimiter ";"
// First tries .298, then .964, falls back to first node
$cli = $cl->clientLike($name, '.298;.964');
$cli->ping();

Cluster operations

// Truncate table across cluster
$result = $cl->truncateTable('dbName.TableName_sharded');

// Random active node
$cl->activeClient()->setTimeout(500);
$cl->activeClient()->write("DROP TABLE IF EXISTS default.asdasdasd ON CLUSTER cluster2");

// Find leader node
$cl->getMasterNodeForTable('dbName.TableName_sharded');

Errors

var_dump($cl->getError());
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.
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
spatie/laravel-javascript-views