Download the PHP package simlux/influxdb-php without Composer
On this page you can find all versions of the php package simlux/influxdb-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download simlux/influxdb-php
More information about simlux/influxdb-php
Files in simlux/influxdb-php
Informations about the package influxdb-php
influxdb-php
InfluxDB client library for PHP
Overview
A easy to use library for using InfluxDB with PHP. Maintained by @thecodeassassin, @gianarb.
The influxdb-php library was created to have php port of the python influxdb client. This way there will be a common abstraction library between different programming languages.
Installation
Installation can be done with composer:
NOTE for PHP 5.3 and PHP 5.4 users
If you use either PHP 5.3 and PHP 5.4, the 0.1.x release is still supported (bug fixes and new release fixes). The 0.1.x branch will work on PHP 5.3 and PHP 5.4 but doesn't contain all the features that the 1.0.0 release has such as UDP support.
Getting started
Initialize a new client object:
This will create a new client object which you can use to read and write points to InfluxDB.
It's also possible to create a client from a DSN (Data Source Name):
Reading
To fetch records from InfluxDB you can do a query directly on a database:
It's also possible to use the QueryBuilder object. This is a class that simplifies the process of building queries.
Make sure that you enter single quotes when doing a where query on strings; otherwise InfluxDB will return an empty result.
You can get the last executed query from the client:
Writing data
Writing data is done by providing an array of points to the writePoints method on a database:
It's possible to add multiple fields when writing measurements to InfluxDB. The point class allows one to easily write data in batches to influxDB.
The name of a measurement and the value are mandatory. Additional fields, tags and a timestamp are optional. InfluxDB takes the current time as the default timestamp.
You can also write multiple fields to a measurement without specifying a value:
Writing data using udp
First, set your InfluxDB host to support incoming UDP sockets:
Then, configure the UDP driver in the client:
Or simply use a DSN (Data Source Name) to send metrics using UDP:
Note: It is import to note that precision will be ignored when you use UDP. You should always use nanosecond precision when writing data to InfluxDB using UDP.
Timestamp precision
It's important to provide the correct precision when adding a timestamp to a Point object. This is because if you specify a timestamp in seconds and the default (nanosecond) precision is set; the entered timestamp will be invalid.
Please note that exec('date + %s%N')
does NOT work under MacOS; you can use PHP's microtime
to get a timestamp with microsecond precision, like such:
Creating databases
When creating a database a default retention policy is added. This retention policy does not have a duration so the data will be flushed with the memory.
This library makes it easy to provide a retention policy when creating a database:
You can also alter retention policies:
and list them:
You can add more retention policies to a database:
Client functions
Some functions are too general for a database. So these are available in the client:
Admin functionality
You can use the client's $client->admin functionality to administer InfluxDB via the API.
List all the users:
Granting and revoking privileges
Granting permissions can be done on both the database level and cluster-wide. To grant a user specific privileges on a database, provide a database object or a database name.
Todo
- More unit tests
- Increase documentation (wiki?)
- Add more features to the query builder
- Add validation to RetentionPolicy
Changelog
1.14.3
- Deprecate IF NOT EXISTS clause in database creation
1.14.2
- Fix Notice when calling InfluxDB\Client::fromDSN without username or password
- fixed Guzzle client timeout is float
- Fix annotation
- Remove unused property
- Fixed misspelling
- Fixed tag with Boolean/Null value trigger parse error
1.4.1
- Fixed bug: Escape field values as per line protocol.
1.4.0
- Updating Influx Database with support for writing direct payloads, thanks @virgofx
1.3.1
- Added ability to write data to a specific retention policy, thanks @virgofx !
1.3.0
- Added quoting of dbname in queries
- Added orderBy to query builder
- Fixed wrong orderby tests
- Travis container-infra and php 7
1.2.2
- Fixed issue with listUsers() method
- Added more unit tests
- Added getColumns method to \InfluxDB\ResultSet
1.2.0
- Added support for 32 bit systems
- Added setters/getters for Point fields
1.1.3
- Added support for symfony3
1.1.2
- Fixed issue with authentication when writing data
1.1.1
- Added support for 0.9.4
- Added if not exists support to database->create()
- Added getLastQuery method
1.1.0
- Added support for 0.9.3 rc2
- Changed the way we handle the datatypes of values
- Changed list retention policies to reflect the changes in 0.9.3
1.0.1
- Added support for authentication in the guzzle driver
- Added admin functionality
1.0.0
- -BREAKING CHANGE- Dropped support for PHP 5.3 and PHP 5.4
- Allowing for custom drivers
- UDP support
0.1.2
- Added exists method to Database class
- Added time precision to database class
0.1.1
- Merged repository to influxdb/influxdb-php
- Added unit test for createRetentionPolicy
- -BREAKING CHANGE- changed $client->db to $client->selectDB
All versions of influxdb-php with dependencies
guzzlehttp/guzzle Version 6.*
symfony/event-dispatcher Version 2.*|3.*