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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle