I have a data access class that sets up three phpcassa connection pools when creating an instance as follows:
try {
$this->cache = new ConnectionPool(
BSCACHE_KEYSPACE,
explode(',', BSCACHE_SERVERS),
null, null, null, null, null,
array(
'username' => BSCACHE_USERNAME,
'password' => BSCACHE_PASSWORD
)
);
$this->indexCache = new ConnectionPool(
INDEXCACHE_KEYSPACE,
explode(',', INDEXCACHE_SERVERS),
null, null, null, null, null,
array(
'username' => INDEXCACHE_USERNAME,
'password' => INDEXCACHE_PASSWORD
)
);
$this->metaCache = new ConnectionPool(
METACACHE_KEYSPACE,
explode(',', METACACHE_SERVERS),
null, null, null, null, null,
array(
'username' => METACACHE_USERNAME,
'password' => METACACHE_PASSWORD
)
);
} catch (Exception $e) {
return array($this->error['connection']);
}
I recently used the code tracing function on the zend php server to conduct a small performance audit of this class and noticed that setting up these three connection pools consumes ~ 100 ms. It is a lot of time to lose setting up a connection, given that each connection is used only once or twice per instance of this class.
Does anyone know any clever tricks that would allow me to create these connection pools once and share them between instances of the class? Maybe there is an easy way to do this, which will happen immediately before more advanced PHP developers?
UPDATE: "" APC, , phpcassa connection.php( 59 v 0.8.a.2)
$socket = new TSocket($host, $port);
... , TSocket () $persist, false. 59 phpcassa, $persist true, . , , , " " - (, cassandra), .