Home

Awesome

Tests Latest Stable Version Latest Unstable Version License

Summary

This library provides a DB layer to communicate to HP Vertica databases for Swoole based applications.

Features supported:

Vertica connections are made through package skatrych/vertica-php-adapter, which is implemented using ODBC. It is not coroutine-friendly, and works in blocking mode only.

This package was derived from our work at Glu Mobile. It has been used in one of our internal microservices talking to Vertica 7.2.0 and 9.3.0 servers, and ran smoothly for months.

Installation

composer require crowdstar/vertica-swoole-adapter

Sample Usage

Following example creates a Vertica connection pool, gets a connection from the pool, makes a database query, then puts the connection back to the pool:

<?php
use CrowdStar\VerticaSwooleAdapter\VerticaAdapter;
use CrowdStar\VerticaSwooleAdapter\VerticaProxy;
use Swoole\ConnectionPool;

$pool = new ConnectionPool(
    function () {
        return new VerticaAdapter($config);
    },
    ConnectionPool::DEFAULT_SIZE,
    VerticaProxy::class
);
/** @var VerticaAdapter $conn */
$conn = $pool->get();
$data = $conn->fetchAll($conn->query($sql)) ?: [];
$pool->put($conn);
?>

For more examples, please check source code under folder examples/. To run the examples, you will need to run following two commands first to install Composer packages and start Docker containers:

docker run --rm -v $(pwd):/var/www -ti phpswoole/swoole:latest-dev composer update -n
docker-compose up --build -d # or "docker-compose up -d" if you don't need to rebuild the image.

Once done, you can run the example(s) using following command(s):

docker exec -ti $(docker ps -qf "name=app") ./examples/example.php
docker exec -ti $(docker ps -qf "name=app") ./examples/benchmark.php
docker exec -ti $(docker ps -qf "name=app") ./examples/test-coroutine-capability.php