public function flush()
{
// depending on config & client version, flush may not be available
try {
/*
* Flush wasn't always properly implemented[1] in the client, plus
* it depends on server config[2] to be enabled. Return status has
* been null in both success & failure cases.
* Flush is a very pervasive function that's likely not called
* lightly. Since it's probably more important to know whether or
* not it succeeded, than having it execute as fast as possible, I'm
* going to add some calls and test if flush succeeded.
*
* 1: https://forums.couchbase.com/t/php-flush-isnt-doing-anything/1886/8
* 2: http://docs.couchbase.com/admin/admin/CLI/CBcli/cbcli-bucket-flush.html
*/
$this->client->upsert('cb-flush-tester', '');
$manager = $this->client->manager();
if (method_exists($manager, 'flush')) {
// ext-couchbase >= 2.0.6
$manager->flush();
} elseif (method_exists($this->client, 'flush')) {
// ext-couchbase < 2.0.6
$this->client->flush();
} else {
return false;
}
} catch (\CouchbaseException $e) {
return false;
}
try {
// cleanup in case flush didn't go through; but if it did, we won't
// be able to remove it and know flush succeeded
$result = $this->client->remove('cb-flush-tester');
return (bool) $result->error;
} catch (\CouchbaseException $e) {
// exception: "The key does not exist on the server"
return true;
}
}