{"id":20260009,"url":"https://github.com/influxdata/influxdb-client-php","last_synced_at":"2025-05-15T02:02:47.058Z","repository":{"id":37458415,"uuid":"169120987","full_name":"influxdata/influxdb-client-php","owner":"influxdata","description":"InfluxDB (v2+) Client Library for PHP","archived":false,"fork":false,"pushed_at":"2025-02-21T15:06:22.000Z","size":4649,"stargazers_count":158,"open_issues_count":7,"forks_count":51,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-06T20:03:28.891Z","etag":null,"topics":["influxdb","php"],"latest_commit_sha":null,"homepage":"https://influxdata.github.io/influxdb-client-php/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/influxdata.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-04T17:47:23.000Z","updated_at":"2025-03-11T18:01:22.000Z","dependencies_parsed_at":"2024-04-16T20:39:32.954Z","dependency_job_id":"9a197f4f-474a-47d0-a6b0-0c8d51ec5b05","html_url":"https://github.com/influxdata/influxdb-client-php","commit_stats":{"total_commits":224,"total_committers":23,"mean_commits":9.73913043478261,"dds":0.3705357142857143,"last_synced_commit":"e7b7c8ededd1e9d868d7b0782e0494bbb4ea741f"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/influxdata","download_url":"https://codeload.github.com/influxdata/influxdb-client-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790470,"owners_count":21162013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["influxdb","php"],"created_at":"2024-11-14T11:17:36.031Z","updated_at":"2025-04-13T22:29:31.865Z","avatar_url":"https://github.com/influxdata.png","language":"PHP","readme":"# influxdb-client-php\n\n[![CircleCI](https://circleci.com/gh/influxdata/influxdb-client-php.svg?style=svg)](https://circleci.com/gh/influxdata/influxdb-client-php)\n[![codecov](https://codecov.io/gh/influxdata/influxdb-client-php/branch/master/graph/badge.svg)](https://codecov.io/gh/influxdata/influxdb-client-php)\n[![Packagist Version](https://img.shields.io/packagist/v/influxdata/influxdb-client-php)](https://packagist.org/packages/influxdata/influxdb-client-php)\n[![License](https://img.shields.io/github/license/influxdata/influxdb-client-php.svg)](https://github.com/influxdata/influxdb-client-php/blob/master/LICENSE)\n[![GitHub issues](https://img.shields.io/github/issues-raw/influxdata/influxdb-client-php.svg)](https://github.com/influxdata/influxdb-client-php/issues)\n[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/influxdata/influxdb-client-php.svg)](https://github.com/influxdata/influxdb-client-php/pulls)\n![PHP from Packagist](https://img.shields.io/packagist/php-v/influxdata/influxdb-client-php)\n[![Slack Status](https://img.shields.io/badge/slack-join_chat-white.svg?logo=slack\u0026style=social)](https://www.influxdata.com/slack)\n\nThis repository contains the reference PHP client for the InfluxDB 2.x.\n\n#### Note: Use this client library with InfluxDB 2.x and InfluxDB 1.8+ ([see details](#influxdb-18-api-compatibility)). For connecting to InfluxDB 1.7 or earlier instances, use the [influxdb-php](https://github.com/influxdata/influxdb-php) client library.\n\n- [Installation](#installation)\n    - [Install the library](#install-the-library)\n- [Usage](#usage)\n    - [Creating a client](#creating-a-client)\n    - [Querying data](#queries)\n    - [Writing data](#writing-data)\n    - [Default Tags](#default-tags)\n- [Advanced Usage](#advanced-usage)\n    - [Check the server status](#check-the-server-status)\n    - [InfluxDB 1.8 API compatibility](#influxdb-18-api-compatibility)\n    - [InfluxDB 2.x management API](#influxdb-2x-management-api)\n    - [Writing via UDP](#writing-via-udp)\n    - [Delete data](#delete-data)\n    - [Proxy and redirects](#proxy-and-redirects)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Documentation\n\nThis section contains links to the client library documentation.\n\n* [Product documentation](https://docs.influxdata.com/influxdb/latest/tools/client-libraries/), [Getting Started](#usage)\n* [Examples](examples)\n* [API Reference](https://influxdata.github.io/influxdb-client-php/) \n* [Changelog](CHANGELOG.md)\n\n## Installation\n\nThe client is not hard coupled to HTTP client library like Guzzle, Buzz or something else. \nThe client uses general abstractions ([PSR-7 - HTTP messages](https://www.php-fig.org/psr/psr-18/),\n[PSR-17 - HTTP factories](https://www.php-fig.org/psr/psr-18/), [PSR-18 - HTTP client](https://www.php-fig.org/psr/psr-18/)) which give you\nfreedom to use your favorite one.\n\n### Install the library\n\nThe InfluxDB 2 client is bundled and hosted on [https://packagist.org/](https://packagist.org/packages/influxdata/influxdb-client-php) and can be installed with composer:\n\n```\ncomposer require influxdata/influxdb-client-php guzzlehttp/guzzle\n```\n\n## Usage\n\n### Creating a client\n\nUse `InfluxDB2\\Client` to create a client connected to a running InfluxDB 2 instance.\n\n```php\n$client = new InfluxDB2\\Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::NS\n]);\n```\n\n#### Client Options\n\n| Option           | Description                                                                                               | Note                                    | Type                              | Default      |\n|------------------|-----------------------------------------------------------------------------------------------------------|-----------------------------------------|-----------------------------------|--------------|\n| **url**          | InfluxDB server API url (e.g. http://localhost:8086)                                                      | **required**                            | String                            | none         |\n| **token**        | Token to use for the authorization                                                                        | **required**                            | String                            | none         |\n| bucket           | Default destination bucket for writes                                                                     |                                         | String                            | none         |\n| org              | Default destination organization for writes                                                               |                                         | String                            | none         |\n| precision        | Default precision for the unix timestamps within the body line-protocol                                   |                                         | String                            | none         |\n| allow_redirects  | Enable HTTP redirects                                                                                     |                                         | bool                              | true         |\n| debug            | Enable verbose logging of http requests                                                                   |                                         | bool                              | false        |\n| logFile          | Default output for logs                                                                                   |                                         | bool                              | php://output |\n| httpClient       | Configured HTTP client to use for communication with InfluxDB                                             |                                         | `Psr\\Http\\Client\\ClientInterface` | none         |\n| verifySSL        | Turn on/off SSL certificate verification. Set to `false` to disable certificate verification.             | :warning: required `Guzzle` HTTP client | bool                              | true         |\n| 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           |\n| proxy            | specify an HTTP proxy, or an array to specify different proxies for different protocols.                  | :warning: required `Guzzle` HTTP client | string                            | none         |\n\n#### Custom HTTP client\n\nThe following code shows how to use and configure [cURL](https://github.com/php-http/curl-client) HTTP client:\n\n##### Install dependencies via composer\n\n```\ncomposer require influxdata/influxdb-client-php nyholm/psr7 php-http/curl-client\n```\n\n##### Configure cURL client\n\n```php\n$curlOptions = [\n    CURLOPT_CONNECTTIMEOUT =\u003e 30, // The number of seconds to wait while trying to connect.\n];\n$curlClient = new Http\\Client\\Curl\\Client(\n    Http\\Discovery\\Psr17FactoryDiscovery::findRequestFactory(),\n    Http\\Discovery\\Psr17FactoryDiscovery::findStreamFactory(),\n    $curlOptions\n);\n```\n\n##### Initialize InfluxDB client\n\n```php\n$client = new Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n    \"httpClient\" =\u003e $curlClient\n]);\n```\n\n### Queries\n\nThe result retrieved by [QueryApi](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/QueryApi.php) could be formatted as a:\n\n   1. Raw query response\n   2. Flux data structure: [FluxTable](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/FluxTable.php), [FluxColumn](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/FluxColumn.php) and [FluxRecord](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/FluxRecord.php)\n   3. Stream of [FluxRecord](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/FluxRecord.php)\n\n#### Query raw\n\nSynchronously executes the Flux query and return result as unprocessed String\n```php\n$this-\u003eclient = new Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"precision\" =\u003e WritePrecision::NS,\n    \"org\" =\u003e \"my-org\",\n    \"debug\" =\u003e false\n]);\n\n$this-\u003equeryApi = $this-\u003eclient-\u003ecreateQueryApi();\n\n$result = $this-\u003equeryApi-\u003equeryRaw(\n            'from(bucket:\"my-bucket\") |\u003e range(start: 1970-01-01T00:00:00.000000001Z) |\u003e last()');\n```\n#### Synchronous query\nSynchronously executes the Flux query and return result as a Array of [FluxTables](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/FluxTable.php)\n```php\n$this-\u003eclient = new Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"precision\" =\u003e WritePrecision::NS,\n    \"org\" =\u003e \"my-org\",\n    \"debug\" =\u003e false\n]);\n\n$this-\u003equeryApi = $this-\u003eclient-\u003ecreateQueryApi();\n\n$result = $this-\u003equeryApi-\u003equery(\n            'from(bucket:\"my-bucket\") |\u003e range(start: 1970-01-01T00:00:00.000000001Z) |\u003e last()');\n```\nThis can then easily be encoded to JSON with [json_encode](https://www.php.net/manual/en/function.json-encode.php)\n```php\nheader('Content-type:application/json;charset=utf-8');\necho json_encode( $result, JSON_PRETTY_PRINT ) ;\n```\n\n#### Query stream\nSynchronously executes the Flux query and return stream of [FluxRecord](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/FluxRecord.php)\n```php\n$this-\u003eclient = new Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"precision\" =\u003e WritePrecision::NS,\n    \"org\" =\u003e \"my-org\",\n    \"debug\" =\u003e false\n]);\n\n$this-\u003equeryApi = $this-\u003eclient-\u003ecreateQueryApi();\n\n$parser = $this-\u003equeryApi-\u003equeryStream(\n            'from(bucket:\"my-bucket\") |\u003e range(start: 1970-01-01T00:00:00.000000001Z) |\u003e last()');\n\nforeach ($parser-\u003eeach() as $record)\n{\n    ...\n}\n```\n### Parameterized queries\nInfluxDB Cloud supports [Parameterized Queries](https://docs.influxdata.com/influxdb/cloud/query-data/parameterized-queries/)\nthat let you dynamically change values in a query using the InfluxDB API. Parameterized queries make Flux queries more\nreusable and can also be used to help prevent injection attacks.\n\nInfluxDB Cloud inserts the params object into the Flux query as a Flux record named `params`. Use dot or bracket\nnotation to access parameters in the `params` record in your Flux query. Parameterized Flux queries support only `int`\n, `float`, and `string` data types. To convert the supported data types into\nother [Flux basic data types, use Flux type conversion functions](https://docs.influxdata.com/influxdb/cloud/query-data/parameterized-queries/#supported-parameter-data-types).\n\nParameterized query example:\n\u003e :warning: Parameterized Queries are supported only in InfluxDB Cloud, currently there is no support in InfluxDB OSS.\n\n```php\n\u003c?php\nrequire __DIR__ . '/../vendor/autoload.php';\n\nuse InfluxDB2\\Client;\nuse InfluxDB2\\Model\\Query;\nuse InfluxDB2\\Point;\nuse InfluxDB2\\WriteType as WriteType;\n\n$url = \"https://us-west-2-1.aws.cloud2.influxdata.com\";\n$organization = 'my-org';\n$bucket = 'my-bucket';\n$token = 'my-token';\n\n$client = new Client([\n    \"url\" =\u003e $url,\n    \"token\" =\u003e $token,\n    \"bucket\" =\u003e $bucket,\n    \"org\" =\u003e $organization,\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::NS,\n    \"debug\" =\u003e false\n]);\n\n$writeApi = $client-\u003ecreateWriteApi([\"writeType\" =\u003e WriteType::SYNCHRONOUS]);\n$queryApi = $client-\u003ecreateQueryApi();\n\n$today = new DateTime(\"now\");\n$yesterday = $today-\u003esub(new DateInterval(\"P1D\"));\n\n$p = new Point(\"temperature\");\n$p-\u003eaddTag(\"location\", \"north\")-\u003eaddField(\"value\", 60)-\u003etime($yesterday);\n$writeApi-\u003ewrite($p);\n$writeApi-\u003eclose();\n\n//\n// Query range start parameter using duration\n//\n$parameterizedQuery = \"from(bucket: params.bucketParam) |\u003e range(start: duration(v: params.startParam))\";\n$query = new Query();\n$query-\u003esetQuery($parameterizedQuery);\n$query-\u003esetParams([\"bucketParam\" =\u003e \"my-bucket\", \"startParam\" =\u003e \"-1d\"]);\n$tables = $queryApi-\u003equery($query);\n\nforeach ($tables as $table) {\n    foreach ($table-\u003erecords as $record) {\n        var_export($record-\u003evalues);\n    }\n}\n\n//\n// Query range start parameter using DateTime\n//\n$parameterizedQuery = \"from(bucket: params.bucketParam) |\u003e range(start: time(v: params.startParam))\";\n$query-\u003esetParams([\"bucketParam\" =\u003e \"my-bucket\", \"startParam\" =\u003e $yesterday]);\n$query-\u003esetQuery($parameterizedQuery);\n$tables = $queryApi-\u003equery($query);\n\nforeach ($tables as $table) {\n    foreach ($table-\u003erecords as $record) {\n        var_export($record-\u003evalues);\n    }\n}\n\n$client-\u003eclose();\n```\n\n### Writing data\n\nThe [WriteApi](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/WriteApi.php) supports \nsynchronous and batching writes into InfluxDB 2.x. In default api uses synchronous write. To enable batching you \ncan use WriteOption.\n\n```php\n$client = new InfluxDB2\\Client([\"url\" =\u003e \"http://localhost:8086\", \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::NS\n]);\n$write_api = $client-\u003ecreateWriteApi();\n$write_api-\u003ewrite('h2o,location=west value=33i 15');\n```\n#### Batching\n\nThe writes are processed in batches which are configurable by `WriteOptions`:\n\n| Property            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Default Value |\n|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|\n| **writeType**       | type of write SYNCHRONOUS / BATCHING /                                                                                                                                                                                                                                                                                                                                                                                                                                       | SYNCHRONOUS   |\n| **batchSize**       | the number of data point to collect in batch                                                                                                                                                                                                                                                                                                                                                                                                                                 | 10            |\n| **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          |\n| **jitterInterval**  | the number of milliseconds before the data is written increased by a random amount                                                                                                                                                                                                                                                                                                                                                                                           | 0             |\n| **maxRetries**      | the number of max retries when write fails                                                                                                                                                                                                                                                                                                                                                                                                                                   | 5             |\n| **maxRetryDelay**   | maximum delay when retrying write in milliseconds                                                                                                                                                                                                                                                                                                                                                                                                                            | 125000        |\n| **maxRetryTime**    | maximum total retry timeout in milliseconds                                                                                                                                                                                                                                                                                                                                                                                                                                  | 180000        |\n| **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             | \n```php\nuse InfluxDB2\\Client;\nuse InfluxDB2\\WriteType as WriteType;\n\n$client = new Client([\"url\" =\u003e \"http://localhost:8086\", \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::NS\n]);\n\n$writeApi = $client-\u003ecreateWriteApi(\n    [\"writeType\" =\u003e WriteType::BATCHING, 'batchSize' =\u003e 1000]);\n\nforeach (range(1, 10000) as $number) {\n    $writeApi-\u003ewrite(\"mem,host=aws_europe,type=batch value=1i $number\");\n}\n\n// flush remaining data\n$writeApi-\u003eclose();\n```\n\n#### Time precision\n\nConfigure default time precision:\n```php\n$client = new InfluxDB2\\Client([\"url\" =\u003e \"http://localhost:8086\", \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n    \"precision\" =\u003e \\InfluxDB2\\Model\\WritePrecision::NS\n]);\n```\n\nConfigure precision per write:\n```php\n$client = new InfluxDB2\\Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n]);\n\n$writeApi = $client-\u003ecreateWriteApi();\n$writeApi-\u003ewrite('h2o,location=west value=33i 15', \\InfluxDB2\\Model\\WritePrecision::MS);\n```\nAllowed values for precision are:\n\n- `WritePrecision::NS` for nanosecond\n- `WritePrecision::US`   for microsecond\n- `WritePrecision::MS`  for millisecond\n- `WritePrecision::S` for second\n\n#### Configure destination\n\nDefault `bucket` and `organization` destination are configured via `InfluxDB2\\Client`:\n\n```php\n$client = new InfluxDB2\\Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n]);\n```\n\nbut there is also possibility to override configuration per write:\n\n```php\n$client = new InfluxDB2\\Client([\"url\" =\u003e \"http://localhost:8086\", \"token\" =\u003e \"my-token\"]);\n\n$writeApi = $client-\u003ecreateWriteApi();\n$writeApi-\u003ewrite('h2o,location=west value=33i 15', \\InfluxDB2\\Model\\WritePrecision::MS, \"production-bucket\", \"customer-1\");\n```\n\n#### Data format\n\nThe data could be written as:\n\n1. `string` that is formatted as a InfluxDB's line protocol\n1. `array` with keys: name, tags, fields and time\n1. [Data Point](https://github.com/influxdata/influxdb-client-php/blob/master/src/InfluxDB2/Point.php) structure\n1. `Array` of above items\n\n```php\n$client = new InfluxDB2\\Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::US\n]);\n\n$writeApi = $client-\u003ecreateWriteApi();\n\n//data in Point structure\n$point=InfluxDB2\\Point::measurement(\"h2o\")\n    -\u003eaddTag(\"location\", \"europe\")\n    -\u003eaddField(\"level\",2)\n    -\u003etime(microtime(true));\n\n$writeApi-\u003ewrite($point);\n\n//data in array structure\n$dataArray = ['name' =\u003e 'cpu', \n    'tags' =\u003e ['host' =\u003e 'server_nl', 'region' =\u003e 'us'],\n    'fields' =\u003e ['internal' =\u003e 5, 'external' =\u003e 6],\n    'time' =\u003e microtime(true)];\n\n$writeApi-\u003ewrite($dataArray);\n\n//write lineprotocol\n$writeApi-\u003ewrite('h2o,location=west value=33i 15');\n```\n\n#### Default Tags\n\nSometimes is useful to store same information in every measurement e.g. `hostname`, `location`, `customer`. \nThe client is able to use static value, app settings or env variable as a tag value.\n\nThe expressions:\n- `California Miner` - static value\n- `${env.hostname}` - environment property\n\n##### Via API\n\n```php\n$this-\u003eclient = new Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"precision\" =\u003e WritePrecision::NS,\n    \"org\" =\u003e \"my-org\",\n    \"tags\" =\u003e ['id' =\u003e '132-987-655', \n        'hostname' =\u003e '${env.Hostname}']\n]);\n\n$writeApi = $this-\u003eclient-\u003ecreateWriteApi(null, ['data_center' =\u003e '${env.data_center}']);\n    \n$writeApi-\u003epointSettings-\u003eaddDefaultTag('customer', 'California Miner');\n\n$point = Point::measurement('h2o')\n            -\u003eaddTag('location', 'europe')\n            -\u003eaddField('level', 2);\n\n$this-\u003ewriteApi-\u003ewrite($point);\n```\n\n## Advanced Usage\n\n### Check the server status \n\nServer availability can be checked using the `$client-\u003eping();` method. That is equivalent of the [influx ping](https://docs.influxdata.com/influxdb/latest/reference/cli/influx/ping/).\n\n### InfluxDB 1.8 API compatibility\n\n[InfluxDB 1.8.0 introduced forward compatibility APIs](https://docs.influxdata.com/influxdb/v1.8/tools/api/#influxdb-2-0-api-compatibility-endpoints) for InfluxDB 2.x. This allow you to easily move from InfluxDB 1.x to InfluxDB 2.x Cloud or open source.\n\nThe following forward compatible APIs are available:\n\n| API                                          | Endpoint                                                                                           | Description                                                                                                                                                                                                                                                    |\n|:---------------------------------------------|:---------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [QueryApi.php](src/InfluxDB2/QueryApi.php)   | [/api/v2/query](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-query-http-endpoint) | Query data in InfluxDB 1.8.0+ using the InfluxDB 2.x API and [Flux](https://docs.influxdata.com/flux/latest/) _(endpoint should be enabled by [`flux-enabled` option](https://docs.influxdata.com/influxdb/latest/administration/config/#flux-enabled-false))_ |\n| [WriteApi.php](src/InfluxDB2/WriteApi.php)   | [/api/v2/write](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-write-http-endpoint) | Write data to InfluxDB 1.8.0+ using the InfluxDB 2.x API                                                                                                                                                                                                       |\n| [HealthApi.php](src/InfluxDB2/HealthApi.php) | [/health](https://docs.influxdata.com/influxdb/latest/tools/api/#health-http-endpoint)             | Check the health of your InfluxDB instance                                                                                                                                                                                                                     |    \n\nFor detail info see [InfluxDB 1.8 example](examples/InfluxDB_18_Example.php).\n\n### InfluxDB 2.x management API\n\nInfluxDB 2.x API client is generated using [`influxdb-clients-apigen`](https://github.com/bonitoo-io/influxdb-clients-apigen). Sources are in `InfluxDB2\\Service\\`  and `InfluxDB2\\Model\\` packages.\n\nThe following example shows how to use `OrganizationService` and `BucketService` to create a new bucket.  \n\n```php\n\nrequire __DIR__ . '/../vendor/autoload.php';\n\nuse InfluxDB2\\Client;\nuse InfluxDB2\\Model\\BucketRetentionRules;\nuse InfluxDB2\\Model\\Organization;\nuse InfluxDB2\\Model\\PostBucketRequest;\nuse InfluxDB2\\Service\\BucketsService;\nuse InfluxDB2\\Service\\OrganizationsService;\n\n$organization = 'my-org';\n$bucket = 'my-bucket';\n$token = 'my-token';\n\n$client = new Client([\n    \"url\" =\u003e \"http://localhost:8086\",\n    \"token\" =\u003e $token,\n    \"bucket\" =\u003e $bucket,\n    \"org\" =\u003e $organization,\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::S\n]);\n\nfunction findMyOrg($client): ?Organization\n{\n    /** @var OrganizationsService $orgService */\n    $orgService = $client-\u003ecreateService(OrganizationsService::class);\n    $orgs = $orgService-\u003egetOrgs()-\u003egetOrgs();\n    foreach ($orgs as $org) {\n        if ($org-\u003egetName() == $client-\u003eoptions[\"org\"]) {\n            return $org;\n        }\n    }\n    return null;\n}\n\n$bucketsService = $client-\u003ecreateService(BucketsService::class);\n\n$rule = new BucketRetentionRules();\n$rule-\u003esetEverySeconds(3600);\n\n$bucketName = \"example-bucket-\" . microtime();\n$bucketRequest = new PostBucketRequest();\n$bucketRequest-\u003esetName($bucketName)\n    -\u003esetRetentionRules([$rule])\n    -\u003esetOrgId(findMyOrg($client)-\u003egetId());\n\n//create bucket\n$respBucket = $bucketsService-\u003epostBuckets($bucketRequest);\nprint $respBucket;\n\n$client-\u003eclose();\n\n\n```\n### Writing via UDP\n\nSending 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.  \nAs is known, sending via UDP occurs without waiting for a response, unlike TCP (HTTP).\n\nUDP Writer Requirements:\n1. Installed ext-sockets\n2. 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\n3. Extra config option passed to client: udpPort. Optionally you can specify udpHost, otherwise udpHost will parsed from url option\n4. Extra config option passed to client: ipVersion. Optionally you can specify the ip version, defaults to IPv4\n \n```php\n$client = new InfluxDB2\\Client([\"url\" =\u003e \"http://localhost:8086\", \"token\" =\u003e \"my-token\",\n    \"bucket\" =\u003e \"my-bucket\",\n    \"org\" =\u003e \"my-org\",\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::NS,\n    \"udpPort\" =\u003e 8094,\n    \"ipVersion\" =\u003e 6,\n]);\n$writer = $client-\u003ecreateUdpWriter();\n$writer-\u003ewrite('h2o,location=west value=33i 15');\n$writer-\u003eclose();\n ```\n\n### Delete data\n\nThe [DefaultService.php](/src/InfluxDB2/Service/DefaultService.php) supports deletes [points](https://docs.influxdata.com/influxdb/latest/reference/syntax/line-protocol/) from an InfluxDB bucket.\n\n```php\n\u003c?php\n/**\n * Shows how to delete data from InfluxDB by client\n */\nuse InfluxDB2\\Client;\nuse InfluxDB2\\Model\\DeletePredicateRequest;\nuse InfluxDB2\\Service\\DeleteService;\n\n$url = 'http://localhost:8086';\n$token = 'my-token';\n$org = 'my-org';\n$bucket = 'my-bucket';\n\n$client = new Client([\n    \"url\" =\u003e $url,\n    \"token\" =\u003e $token,\n    \"bucket\" =\u003e $bucket,\n    \"org\" =\u003e $org,\n    \"precision\" =\u003e InfluxDB2\\Model\\WritePrecision::S\n]);\n\n//\n// Delete data by measurement and tag value\n//\n/** @var DeleteService $service */\n$service = $client-\u003ecreateService(DeleteService::class);\n\n$predicate = new DeletePredicateRequest();\n$predicate-\u003esetStart(DateTime::createFromFormat('Y', '2020'));\n$predicate-\u003esetStop(new DateTime());\n$predicate-\u003esetPredicate(\"_measurement=\\\"mem\\\" AND host=\\\"host1\\\"\");\n\n$service-\u003epostDelete($predicate, null, $org, $bucket);\n\n$client-\u003eclose();\n```\n\nFor more details see [DeleteDataExample.php](examples/DeleteDataExample.php).\n\n### Proxy and redirects\n\nYou can configure InfluxDB PHP client behind a proxy in two ways:\n\n##### 1. Using environment variable\nSet environment variable `HTTP_PROXY` or `HTTPS_PROXY` based on the scheme of your server url. For more info see Guzzle docs - [environment Variables](https://docs.guzzlephp.org/en/5.3/clients.html?highlight=PROXY#environment-variables).\n\n##### 2. Configure client to use proxy via Options\nYou can pass a `proxy` configuration when creating the client:\n```php\n$client = new InfluxDB2\\Client([\n  \"url\" =\u003e \"http://localhost:8086\", \n  \"token\" =\u003e \"my-token\",\n  \"bucket\" =\u003e \"my-bucket\",\n  \"org\" =\u003e \"my-org\",\n  \"proxy\" =\u003e \"http://192.168.16.1:10\",\n]);\n```\nFor more info see Guzzle docs - [proxy](https://docs.guzzlephp.org/en/5.3/clients.html?highlight=PROXY#proxy).\n\n#### Redirects\n\nClient automatically follows HTTP redirects. You can configure redirects behaviour by  a `allow_redirects` configuration:\n```php\n$client = new InfluxDB2\\Client([\n  \"url\" =\u003e \"http://localhost:8086\", \n  \"token\" =\u003e \"my-token\",\n  \"bucket\" =\u003e \"my-bucket\",\n  \"org\" =\u003e \"my-org\",\n  \"allow_redirects\" =\u003e false,\n]);\n```\nFor more info see Redirect Plugin docs - [allow_redirects](https://docs.php-http.org/en/latest/plugins/redirect.html#redirect-plugin)\n\n## Local tests\n\nRun once to install dependencies:\n\n```shell script\nmake deps\n```\n\nRun unit \u0026 intergration tests:\n\n```shell script\nmake test\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/influxdata/influxdb-client-php.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Finfluxdb-client-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfluxdata%2Finfluxdb-client-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Finfluxdb-client-php/lists"}