Download the PHP package influxdata/influxdb-client-php without Composer

On this page you can find all versions of the php package influxdata/influxdb-client-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package influxdb-client-php

influxdb-client-php

CircleCI codecov Packagist Version License GitHub issues GitHub pull requests PHP from Packagist Slack Status

This repository contains the reference PHP client for the InfluxDB 2.x.

Note: Use this client library with InfluxDB 2.x and InfluxDB 1.8+ (influxdb-php client library.

Documentation

This section contains links to the client library documentation.

Installation

The client is not hard coupled to HTTP client library like Guzzle, Buzz or something else. The client uses general abstractions (PSR-7 - HTTP messages, PSR-17 - HTTP factories, PSR-18 - HTTP client) which give you freedom to use your favorite one.

Install the library

The InfluxDB 2 client is bundled and hosted on https://packagist.org/ and can be installed with composer:

Usage

Creating a client

Use InfluxDB2\Client to create a client connected to a running InfluxDB 2 instance.

Client Options

Option Description Note Type Default
url InfluxDB server API url (e.g. http://localhost:8086) required String none
token Token to use for the authorization required String none
bucket Default destination bucket for writes String none
org Default destination organization for writes String none
precision Default precision for the unix timestamps within the body line-protocol String none
allow_redirects Enable HTTP redirects bool true
debug Enable verbose logging of http requests bool false
logFile Default output for logs bool php://output
httpClient Configured HTTP client to use for communication with InfluxDB Psr\Http\Client\ClientInterface none
verifySSL Turn on/off SSL certificate verification. Set to false to disable certificate verification. :warning: required Guzzle HTTP client bool true
timeout Describing the number of seconds to wait while trying to connect to a server. Use 0 to wait indefinitely. :warning: required Guzzle HTTP client int 10
proxy specify an HTTP proxy, or an array to specify different proxies for different protocols. :warning: required Guzzle HTTP client string none

Custom HTTP client

The following code shows how to use and configure cURL HTTP client:

Install dependencies via composer
Configure cURL client
Initialize InfluxDB client

Queries

The result retrieved by QueryApi could be formatted as a:

  1. Raw query response
  2. Flux data structure: FluxTable, FluxColumn and FluxRecord
  3. Stream of FluxRecord

Query raw

Synchronously executes the Flux query and return result as unprocessed String

Synchronous query

Synchronously executes the Flux query and return result as a Array of FluxTables

This can then easily be encoded to JSON with json_encode

Query stream

Synchronously executes the Flux query and return stream of FluxRecord

Parameterized queries

InfluxDB Cloud supports Parameterized Queries that let you dynamically change values in a query using the InfluxDB API. Parameterized queries make Flux queries more reusable and can also be used to help prevent injection attacks.

InfluxDB Cloud inserts the params object into the Flux query as a Flux record named params. Use dot or bracket notation to access parameters in the params record in your Flux query. Parameterized Flux queries support only int , float, and string data types. To convert the supported data types into other Flux basic data types, use Flux type conversion functions.

Parameterized query example:

:warning: Parameterized Queries are supported only in InfluxDB Cloud, currently there is no support in InfluxDB OSS.

Writing data

The WriteApi supports synchronous and batching writes into InfluxDB 2.x. In default api uses synchronous write. To enable batching you can use WriteOption.

Batching

The writes are processed in batches which are configurable by WriteOptions:

Property Description Default Value
writeType type of write SYNCHRONOUS / BATCHING / SYNCHRONOUS
batchSize the number of data point to collect in batch 10
retryInterval the number of milliseconds to retry unsuccessful write. The retry interval is "exponentially" used when the InfluxDB server does not specify "Retry-After" header. 5000
jitterInterval the number of milliseconds before the data is written increased by a random amount 0
maxRetries the number of max retries when write fails 5
maxRetryDelay maximum delay when retrying write in milliseconds 125000
maxRetryTime maximum total retry timeout in milliseconds 180000
exponentialBase the base for the exponential retry delay, the next delay is computed using random exponential backoff as a random value within the interval retryInterval * exponentialBase^(attempts-1) and retryInterval * exponentialBase^(attempts). Example for retryInterval=5000, exponentialBase=2, maxRetryDelay=125000, total=5 Retry delays are random distributed values within the ranges of [5000-10000, 10000-20000, 20000-40000, 40000-80000, 80000-125000] 2

Time precision

Configure default time precision:

Configure precision per write:

Allowed values for precision are:

Configure destination

Default bucket and organization destination are configured via InfluxDB2\Client:

but there is also possibility to override configuration per write:

Data format

The data could be written as:

  1. string that is formatted as a InfluxDB's line protocol
  2. array with keys: name, tags, fields and time
  3. Data Point structure
  4. Array of above items

Default Tags

Sometimes is useful to store same information in every measurement e.g. hostname, location, customer. The client is able to use static value, app settings or env variable as a tag value.

The expressions:

Via API

Advanced Usage

Check the server status

Server availability can be checked using the $client->ping(); method. That is equivalent of the influx ping.

InfluxDB 1.8 API compatibility

InfluxDB 1.8.0 introduced forward compatibility APIs for InfluxDB 2.x. This allow you to easily move from InfluxDB 1.x to InfluxDB 2.x Cloud or open source.

The following forward compatible APIs are available:

API Endpoint Description
QueryApi.php /api/v2/query Query data in InfluxDB 1.8.0+ using the InfluxDB 2.x API and Flux (endpoint should be enabled by flux-enabled option)
WriteApi.php /api/v2/write Write data to InfluxDB 1.8.0+ using the InfluxDB 2.x API
HealthApi.php /health Check the health of your InfluxDB instance

For detail info see InfluxDB 1.8 example.

InfluxDB 2.x management API

InfluxDB 2.x API client is generated using influxdb-clients-apigen. Sources are in InfluxDB2\Service\ and InfluxDB2\Model\ packages.

The following example shows how to use OrganizationService and BucketService to create a new bucket.

Writing via UDP

Sending via UDP will be useful in cases when the execution time is critical to avoid potential delays (even timeouts) in sending metrics to the InfluxDB while are problems with the database or network connectivity.
As is known, sending via UDP occurs without waiting for a response, unlike TCP (HTTP).

UDP Writer Requirements:

  1. Installed ext-sockets
  2. Since Influxdb 2.0+ does not support UDP protocol natively you need to install and configure Telegraf plugin: https://docs.influxdata.com/telegraf/v1.16/plugins/#socket_listener
  3. Extra config option passed to client: udpPort. Optionally you can specify udpHost, otherwise udpHost will parsed from url option
  4. Extra config option passed to client: ipVersion. Optionally you can specify the ip version, defaults to IPv4

Delete data

The points from an InfluxDB bucket.

For more details see DeleteDataExample.php.

Proxy and redirects

You can configure InfluxDB PHP client behind a proxy in two ways:

1. Using environment variable

Set environment variable HTTP_PROXY or HTTPS_PROXY based on the scheme of your server url. For more info see Guzzle docs - environment Variables.

2. Configure client to use proxy via Options

You can pass a proxy configuration when creating the client:

For more info see Guzzle docs - proxy.

Redirects

Client automatically follows HTTP redirects. You can configure redirects behaviour by a allow_redirects configuration:

For more info see Redirect Plugin docs - allow_redirects

Local tests

Run once to install dependencies:

Run unit & intergration tests:

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/influxdata/influxdb-client-php.

License

The gem is available as open source under the terms of the MIT License.


All versions of influxdb-client-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-curl Version *
ext-json Version *
ext-mbstring Version *
php-http/client-common Version ^2.2.1
php-http/discovery Version ^1.9.1
psr/http-client Version ^1.0.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package influxdata/influxdb-client-php contains the following files

Loading the files please wait ....