Download the PHP package influxdb/influxdb-php without Composer
On this page you can find all versions of the php package influxdb/influxdb-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download influxdb/influxdb-php
More information about influxdb/influxdb-php
Files in influxdb/influxdb-php
Informations about the package influxdb-php
The v1 client libraries for InfluxDB were typically developed and maintained by community members. They have all now been succeeded by v2 client libraries. They are being archived it in favor of the v2 client library. See https://github.com/influxdata/influxdb-php/issues/171.
If there are still users of this v1 client library, and they or somebody else are willing to keep them updated with security fixes at a minimum please reach out on the Community Forums or InfluxData Slack.
influxdb-php
InfluxDB client library for PHP
Note: This library is for use with InfluxDB 1.x. For connecting to InfluxDB 2.x instances, please use the influxdb-client-php client.
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):
Important: don't forget to urlencode()
the password (and username for that matter) when using a DSN,
especially if it contains non-alphanumeric characters. Not doing so might cause exceptions to be thrown.
Reading data
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:
Reading data using a timeout
In production if you are querying InfluxDB to generate a response to a web or API request, you may want to set a specific timeout for InfluxDB calls rather than the default of letting them run indefinitely.
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.15.0
- Added cURL driver support #122 (thanks @aldas)
- Improved query error message #129 (thanks @andreasanta)
1.14.8
- Merged #122
1.14.7
- Added offset in QueryBuilder (thanks @lifekent and @BentCoder)
1.14.6
- dependencies update (#97), by @aldas
- Adding timeout information. (#103), by @NickBusey
- Add ability to specify connect_timeout for guzzle (#105), by @brycefranzen
1.14.5
- Update key concepts link to point to the proper place.
- Replace costly array_merge calls with foreach + array operator
- Add getter method for verifySSL
- Support for Symfony 4
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