Download the PHP package the-tinderbox/clickhouse-php-client without Composer
On this page you can find all versions of the php package the-tinderbox/clickhouse-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download the-tinderbox/clickhouse-php-client
More information about the-tinderbox/clickhouse-php-client
Files in the-tinderbox/clickhouse-php-client
Package clickhouse-php-client
Short Description Clickhouse client over HTTP
License
Informations about the package clickhouse-php-client
Clickhouse Client
Package was written as client for Clickhouse.
Client uses Guzzle for sending Http requests to Clickhouse servers.
Requirements
php7.1
Install
Composer
Usage
Client works with alone server and cluster. Also, client can make async select and insert (from local files) queries.
Alone server
Cluster
Before execute any query on cluster, you should provide cluster name and client will run all queries on specified cluster.
By default client will use random server in given list of servers or in specified cluster. If you want to perform request on specified server you should use
using($hostname)
method on client and then run query. Client will remember hostname for next queries:
Server tags
To use server with tag, you should call function before execute any query.
Select queries
Any SELECT query will return instance of Result
. This class implements interfaces \ArrayAccess
, \Countable
и \Iterator
,
which means that it can be used as an array.
Array with result rows can be obtained via rows
property
Also you can get some statistic of your query execution:
- Number of read rows
- Number of read bytes
- Time of query execution
- Rows before limit at least
Statistic can be obtained via statistic
property
Sync
Using local files
You can use local files as temporary tables in Clickhouse. You should pass as third argument array of TempTable
instances.
instance.
In this case will be sent one file to the server from which Clickhouse will extract data to temporary table. Structure of table will be:
- number - UInt64
If you pass such an array as a structure:
Then each column from file wil be named as _1, _2, _3.
You can provide path to file or pass FileInterface
instance as second argument.
There is some other types of file streams which could be used to send to server:
- File - simple file stored on disk;
- FileFromString - stream created from string. For example:
new FileFromString('1'.PHP_EOL.'2'.PHP_EOL.'3'.PHP_EOL)
- MergedFiles - stream which includes many files and merges them all in one. You should pass to constructor file path, which contains list of files which should be megred in one stream.
- TempTable - wrapper to any of
FileInterface
instance and contains structure. Usefull to make inserts using withMergedFiles
.
Async
Unlike the readOne
method, which returnsResult
, the read
method returns an array ofResult
for each executed query.
In read
method, you can pass the parameter $concurrency
which is responsible for the maximum simultaneous number of requests.
Using local files
As with synchronous select request you can pass files to the server:
With asynchronous requests you can pass multiple files as with synchronous request.
Insert queries
Insert queries always returns true or throws exceptions in case of error.
Data can be written row by row or from local CSV or TSV files.
In case of writeFiles
queries executes asynchronously. If you have butch of files and you want to insert them in one insert query, you can
use our ccat
utility and MergedFiles
instance instead of File
. You should put list of files to insert into
one file:
Building ccat
ccat
sources placed into utils/ccat
directory. Just run make && make install
to build and install library into
bin
directory of package. There are already compiled binary of ccat
in bin
directory, but it
may not work on some systems.
In writeFiles
method, you can pass the parameter $concurrency
which is responsible for the maximum simultaneous number of requests.
Other queries
In addition to SELECT and INSERT queries, you can execute other queries :) There is statement
method for this purposes.
Testing
Roadmap
- Add ability to save query result in local file
Contributing
Please send your own pull-requests and make suggestions on how to improve anything. We will be very grateful.
Thx!