1. Go to this page and download the library: Download corley/influxdb-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
corley / influxdb-sdk example snippets
$client->mark("app-search", [
"key" => "this is my search"
]);
$results = $client->query('select * from "app-search"');
$reader = ...
$options = new Udp\Options();
$writer = new Udp\Writer($options);
$client = new Client($reader, $writer);
$http = new \GuzzleHttp\Client();
$writer = ...
$options = new Http\Options();
$reader = new Http\Reader($http, $options);
$client = new Client($reader, $writer);
$reader = new Http\Reader($http, $httpOptions);
$writer = new Udp\Writer($udpOptions);
$client = new Client($reader, $writer);
$client->mark(...); // Use UDP/IP support
$client->query("SELECT * FROM my_serie"); // Use HTTP support
$reader = new Http\Reader($http, $options);
$writer = new Http\Writer($http, $options);
$client = new Client($reader, $writer);
$client->mark(...); // Use HTTP support
$client->query("SELECT * FROM my_serie"); // Use HTTP support
$option->setHost("proxy.influxdb.tld");
$option->setPort(80);
$option->setPrefix("/influxdb"); // your prefix is: /influxdb
// final url will be: http://proxy.influxdb.tld:80/influxdb/write
$client->mark("serie", ["data" => "my-data"]);
$client->mark("serie", [
"value" => 12, // Marked as int64
"elem" => 12.4, // Marked as float64
]);
$client->mark("serie", [
"value" => new IntType(12), // Marked as int64
"elem" => new FloatType(12.4), // Marked as float64
"status" => new BoolType(true), // Marked as boolean
"line" => new StringType("12w"), // Marked as string
]);
$qb = $conn->createQueryBuilder();
$qb->select("*")
->from("cpu_load_short")
->where("time = ?")
->setParameter(0, 1434055562000000000);
$data = $qb->execute();
foreach ($data->fetchAll() as $element) {
// Use your element
}
$manager = new Manager($client); // InfluxDB\Client instance
$manager->addQuery("getExceptionsInMinutes", function($minutes) {
return "SELECT * FROM app_exceptions WHERE time > now() - {$minutes}m";
});
$manager->getExceptionsInMinutes(10); // The callable name
class GetExceptionsInMinutes
{
public function __invoke($minutes)
{
return "SELECT * FROM app_exceptions WHERE time > now() - {$minutes}m";
}
public function __toString()
{
return "getExceptionsInMinutes";
}
}
$manager->addQuery(new GetExceptionsInMinutes());
$manager->getExceptionsInMinutes(10); //Use the query