You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After the initial connection to one of the hosts specified via `withContactPoints` succeeded, the driver discovers the addresses and connects to all members of the cluster automatically. You can also see the nodes that the driver discovered by running `SELECT * FROM system.peers`.
21
+
After the initial connection to one of the hosts specified via `withContactPoints()` succeeded, the driver discovers the addresses and connects to all members of the cluster automatically. You can also see the nodes that the driver discovered by running `SELECT * FROM system.peers`.
22
+
23
+
### Configuring load balancing policy
24
+
25
+
PHP Driver comes with a variety of load balancing policies. By default it uses a combination of token aware data center round robin.
26
+
27
+
The token aware load balancing policy uses the same hashing algorithms as the Apache Cassandra to route prepared statements execution directly to replica nodes, avoiding an additional network hop to/from the coordinator. You can toggle its usage with [`Cassandra\Cluster\Builder::withTokenAwareRouting()`](http://datastax.github.io/php-driver/api/class/Cassandra/Cluster/Builder/#with-token-aware-routing).
28
+
29
+
```php
30
+
<?php
31
+
32
+
$cluster = Cassandra::cluster()
33
+
->withTokenAwareRouting(false)
34
+
->build();
35
+
$session = $cluster->connect();
36
+
```
37
+
38
+
The default datacenter aware round robin load balancing policy is configured to keep all traffic in the same datacenter. Upon connecting to a host from the initial list of contact points, the driver will consider that host's datacenter to be local. Only hosts from the same datacenter will be connected to and used for executing statements. You can override the name of the local datacenter. The number of hosts from remote datacenters that the driver may use and whether it should execute statements with local consistencies on those hosts in case none of the local hosts are available. All of that is configurable via [`Cassandra\Cluster\Builder::withDatacenterAwareRoundRobinLoadBalancingPolicy()`](http://datastax.github.io/php-driver/api/class/Cassandra/Cluster/Builder/#with-datacenter-aware-round-robin-load-balancing-policy).
Finally, you may disable datacenter awareness by calling [`Cassandra\Cluster\Builder::withRoundRobinLoadBalancingPolicy()`](http://datastax.github.io/php-driver/api/class/Cassandra/Cluster/Builder/#with-round-robin-load-balancing-policy).
50
+
51
+
```php
52
+
<?php
53
+
54
+
$cluster = Cassandra::cluster()
55
+
->withRoundRobinLoadBalancingPolicy()
56
+
->build();
57
+
$session = $cluster->connect();
58
+
```
59
+
60
+
### Authenticating via `PasswordAuthenticator`
61
+
62
+
The PHP Driver supports Apache Cassandra's built-in password authentication mechanism. To enable it, use [`Cassandra\Cluster\Builder::withCredentials()`](http://datastax.github.io/php-driver/api/class/Cassandra/Cluster/Builder/#with-credentials).
63
+
64
+
```php
65
+
<?php
66
+
67
+
$cluster = Cassandra::cluster()
68
+
->withCredentials("username", "password")
69
+
->build();
70
+
$session = $cluster->connect();
71
+
```
72
+
73
+
### Enabling SSL encryption
74
+
75
+
The PHP Driver supports SSL encryption of network connections. You must configure [`Cassandra\SSLOptions`](http://datastax.github.io/php-driver/api/class/Cassandra/SSLOptions/) using the [`Cassandra\SSLOptions\Builder`](http://datastax.github.io/php-driver/api/class/Cassandra/SSLOptions/Builder/).
@@ -75,8 +144,8 @@ With fully asynchronous api, it is very easy to run queries in parallel:
75
144
<?php
76
145
77
146
$data = array(
78
-
array(41, 'Sam'),
79
-
array(35, 'Bob')
147
+
array(41, 'Sam'),
148
+
array(35, 'Bob')
80
149
);
81
150
82
151
$statement = $session->prepare("UPDATE users SET age = ? WHERE user_name = ?");
@@ -85,15 +154,15 @@ $timeout = 5;
85
154
86
155
// execute all statements in background
87
156
foreach ($data as $arguments) {
88
-
$futures[]= $session->executeAsync($statement, new ExecutionOptions(
89
-
'arguments' => $arguments
90
-
));
157
+
$futures[]= $session->executeAsync($statement, new ExecutionOptions(
158
+
'arguments' => $arguments
159
+
));
91
160
}
92
161
93
162
// wait for all statements to complete
94
163
foreach ($futures as $future) {
95
-
// we will not wait for each result for more than 5 seconds
96
-
$future->get(5);
164
+
// we will not wait for each result for more than 5 seconds
165
+
$future->get(5);
97
166
}
98
167
```
99
168
@@ -171,7 +240,20 @@ Cassandra 1.2 also supported batching, but only as a CQL feature, you had to bui
171
240
172
241
### Result paging
173
242
174
-
If you're using Cassandra 2.0 or later you can page your query results by adding the `page_size` option to [`Cassandra\ExecutionOptions`](http://datastax.github.io/php-driver/api/class/Cassandra/ExecutionOptions/):
243
+
**If you're using Cassandra 2.0** or later you can page your query results.
244
+
245
+
By default, a page size of 10000 will be used, you can override the default page size via [`Cassandra\Cluster\Builder::withDefaultPageSize()`](http://datastax.github.io/php-driver/api/class/Cassandra/Cluster/Builder/#with-default-page-size).
246
+
247
+
```php
248
+
<?php
249
+
250
+
$cluster = Cassandra::cluster()
251
+
->withDefaultPageSize(200)
252
+
->build();
253
+
$session = $cluster->connect();
254
+
```
255
+
256
+
You can also override the page size on a per-execute basis by adding the `page_size` option to [`Cassandra\ExecutionOptions`](http://datastax.github.io/php-driver/api/class/Cassandra/ExecutionOptions/):
175
257
176
258
```php
177
259
<?php
@@ -180,10 +262,10 @@ $statement = new Cassandra\SimpleStatement("SELECT * FROM large_table WHERE id =
180
262
$result = $session->execute($statement, new Cassandra\ExecutionOptions(array('page_size' => 100)));
181
263
182
264
while ($result) {
183
-
foreach ($result as $row) {
184
-
var_dump($row);
185
-
}
186
-
$result = $result->nextPage();
265
+
foreach ($result as $row) {
266
+
var_dump($row);
267
+
}
268
+
$result = $result->nextPage();
187
269
}
188
270
```
189
271
@@ -210,24 +292,25 @@ Consistency can also be passed via `Cassandra\ExecutionOptions`.
210
292
<?php
211
293
212
294
$session->execute(
213
-
new Cassandra\SimpleStatement('SELECT * FROM users'),
214
-
new Cassandra\ExecutionOptions(array('consistency' => Cassandra::CONSISTENCY_LOCAL_QUORUM))
295
+
new Cassandra\SimpleStatement('SELECT * FROM users'),
296
+
new Cassandra\ExecutionOptions(array('consistency' => Cassandra::CONSISTENCY_LOCAL_QUORUM))
215
297
);
216
298
217
299
$statement = $session->prepare('SELECT * FROM users');
218
300
$session->execute($statement, new Cassandra\ExecutionOptions(array(
0 commit comments