An independent client for Kibilog.com, running on native code.

Overview

The library is a client for working with Kibilog.com

The client works without cUrl. To work, it is necessary that in php.ini there is a setting allow_url_fopen = 1

Detailed examples

Example:

setCreatedAt(time()) /** * If necessary, additional parameters can be registered to form an * array with scalar values. * Optional. */ ->setParams( [ 'createdAt' => date("F d Y H:i:s.", filemtime($sFilepath)), 'filesize' => round($sFilepath / 1024, 3) ] ) /** * Log entry level according to RFC 5424 standard. * Optional. By default INFO. */ ->setLevel(Message\Monolog::LEVEL_INFO) /** * A group of messages. * Optional. */ ->setGroup($sUuidIteration); /** * Let's add the message to the collection. */ $oClient->addMessage($oMessage); try { if (filesize($sFilepath) < 1024) { $oClient->addMessage( (new Message\Monolog( $sLogUlid, 'The image is suspiciously small. Let\'s skip it.' )) ->setGroup($sUuidIteration) ->setGroup(Message\Monolog::LEVEL_WARNING) ); } // Some kind of logic // ... $oMessage = null; if ($isResultSuccess) { $oMessage = (new Message\Monolog( $sLogUlid, 'Done' )); } else { $oMessage = (new Message\Monolog( $sLogUlid, 'Error' ))->setLevel(Message\Monolog::LEVEL_ERROR); } $oMessage ->setGroup($sUuidIteration) ->setParams([ 'executeTime' => round(microtime() - $iTime, 4) ]); $oClient->addMessage($oMessage); } catch (\Throwable $e) { $oClient->addMessage( (new Message\Monolog( $sLogUlid, 'Exception: '.$e->getMessage() )) ->setParams( [ 'trace' => array_map(function ($v) { return (!empty($v['class']) ? $v['class'].'->' : '') .implode( ' ', [ $v['function'].'()', 'IN', $v['file'], $v['line'] ] ); }, $e->getTrace()) ] ) ->setLevel(Message\Monolog::LEVEL_CRITICAL) ); } finally { /** * We will send the collected messages. * After sending, the internal collection will be reset and it * can be reassembled. * Important: You can add messages to the collection that are * intended for different logs (with different гдшв). In fact, * it's even better - by sending messages in large groups, you * save time on the connection. * But it should be understood that collecting a large number of * messages consumes RAM, so find a balance so as not to get a * leak of RAM. */ $oClient->sendMessages(); } } ">
use Kibilog\SimpleClient\Fallback\Adapter\FilesystemAdapter;
use Kibilog\SimpleClient\HttpClient;
use Kibilog\SimpleClient\Message;

/**
 * Initializing the client.
 */
$sUserToken = '01fdeleozya3fwa1nwy9b2w034';
$oClient = new HttpClient($sUserToken);

/**
 * Set timeout connection.
 * Default 2 seconds.
 * Optional.
 */
$oClient->setHttpTimeout(5);

/**
 * Fallback is designed not to lose data in case
 *   of network problems or service availability.
 * Optional.
 */
$oClient->setFallback(
    new FilesystemAdapter(dirname($_SERVER['DOCUMENT_ROOT']).'/kibilogFallback')
);

/**
 * If the program crashes, we will try to send
 *   all the collected messages.
 * Optional.
 */
register_shutdown_function(function () use ($oClient)
    {
        $oClient->sendMessages();
    }
);

// As an example, let's go through the files and try to convert them.
$sDir = $_SERVER['DOCUMENT_ROOT'].'/images/';
$aFiles = glob($sDir.'*');
foreach ($aFiles as $sFile) {
    $sFilepath = $sDir.$sFile;
    $iTime = microtime();

    $sLogUlid = '01fjqbwk1heyv50z99hkg7m6ky';

    /**
     * If we need to group messages (as part of this example, grouping messages within the
     *   framework of working with a single file), we need to form a message group value.
     * The group value must be UUID version 4.
     */
    $sUuidIteration = \Kibilog\SimpleClient\Assistent\Uuid::v4();

    $oMessage = (new Message\Monolog(
        $sLogUlid,
        'Starting processing the file "'.$sFile.'".'
    ))
        /**
         * By default, time(). It is set automatically during creation.
         * It makes sense to set when transmitting messages with a timestamp (for example, nginx log).
         * There must be a timestamp with UTC timezone.
         * Optional.
         */
        ->setCreatedAt(time())
        /**
         * If necessary, additional parameters can be registered to form an
         *   array with scalar values.
         * Optional.
         */
        ->setParams(
            [
                'createdAt' => date("F d Y H:i:s.", filemtime($sFilepath)),
                'filesize' => round($sFilepath / 1024, 3)
            ]
        )
        /**
         * Log entry level according to RFC 5424 standard.
         * Optional. By default INFO.
         */
        ->setLevel(Message\Monolog::LEVEL_INFO)
        /**
         * A group of messages.
         * Optional.
         */
        ->setGroup($sUuidIteration);
    /**
     * Let's add the message to the collection.
     */
    $oClient->addMessage($oMessage);


    try {
        if (filesize($sFilepath) < 1024) {
            $oClient->addMessage(
                (new Message\Monolog(
                    $sLogUlid,
                    'The image is suspiciously small. Let\'s skip it.'
                ))
                    ->setGroup($sUuidIteration)
                    ->setGroup(Message\Monolog::LEVEL_WARNING)
            );
        }

        // Some kind of logic
        // ...
        
        $oMessage = null;
        if ($isResultSuccess) {
            $oMessage = (new Message\Monolog(
                $sLogUlid,
                'Done'
            ));
        } else {
            $oMessage = (new Message\Monolog(
                $sLogUlid,
                'Error'
            ))->setLevel(Message\Monolog::LEVEL_ERROR);
        }

        $oMessage
            ->setGroup($sUuidIteration)
            ->setParams([
                'executeTime' => round(microtime() - $iTime, 4)
            ]);
        $oClient->addMessage($oMessage);
    } catch (\Throwable $e) {
        $oClient->addMessage(
            (new Message\Monolog(
                $sLogUlid,
                'Exception: '.$e->getMessage()
            ))
                ->setParams(
                    [
                        'trace' => array_map(function ($v)
                            {
                                return (!empty($v['class']) ? $v['class'].'->' : '')
                                       .implode(
                                           ' ',
                                           [
                                               $v['function'].'()',
                                               'IN',
                                               $v['file'],
                                               $v['line']
                                           ]
                                       );
                            }, $e->getTrace())
                    ]
                )
                ->setLevel(Message\Monolog::LEVEL_CRITICAL)
        );
    }
    finally {
        /**
         * We will send the collected messages.
         * After sending, the internal collection will be reset and it
         *   can be reassembled.
         * Important: You can add messages to the collection that are
         *   intended for different logs (with different гдшв). In fact,
         *   it's even better - by sending messages in large groups, you
         *   save time on the connection.
         * But it should be understood that collecting a large number of
         *   messages consumes RAM, so find a balance so as not to get a
         *   leak of RAM.
         */
        $oClient->sendMessages();
    }
}
You might also like...
PHP client for Microsoft Azure Face API.

Microsoft Azure Face API PHP client A PHP library that utilizes Azure Face REST API. Requirements PHP = 7.4 Installation composer require darmen/php-

Google PHP API Client Services

Google PHP API Client Services

AltiriaSmsPhpClient, the official PHP client of Altiria
AltiriaSmsPhpClient, the official PHP client of Altiria

Altiria, cliente SMS PHP Altiria SMS PHP es un cliente que simplifica al máximo la integración de nuestro API para PHP. Por el momento, esta librería

A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP
A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP

A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP. Including adding reviews to a store's products. It is used to import and export reviews through the API. This is the official package built and developed by A2Reviews, Inc.

PHP Client for the GoFlink API

GoFlink PHP API Client This project is an unofficial library to communicate with the GoFlink API from your PHP project. Documentation about the API is

A PHP client for the official Kizeo Forms API V3+. 📌

Kizeo Forms API V3+ - PHP This is a Swagger generated doc for Kizeo REST API 3. You can find additionnal documentation here : Online documentation. Th

json-rpc client base on http

laravel JSON-RPC客户端(Http协议) 本项目是基于JSON-RPC的服务端端实现的rpc客户端 server端见:https://sajya.github.io/ 初始化 发布 php artisan vendor:publish --provider="Ze\JsonRpcCli

Client for the Tenant Security Proxy in PHP

Tenant Security Client PHP Library A PHP client for implementing CMK within a vendor's infrastructure. Makes requests through an IronCore Tenant Secur

⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.
⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC. This project is a work-in-progress. Code and docume

Owner
null
PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

Sergey Bykov 63 Feb 14, 2022
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023
Code Quiz MonoRepo (API, API Client, App)

Code Quiz Welcome to the Code Quiz Open Source project from How To Code Well. This is an Open Source project that includes an API and an App for the d

How To Code Well 2 Nov 20, 2022
A simple PHP GitHub API client, Object Oriented, tested and documented.

PHP GitHub API A simple Object Oriented wrapper for GitHub API, written with PHP. Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is

KNP Labs 2k Jan 7, 2023
A simple Object Oriented PHP Client for Termii SMS API

Termii Client A simple Object Oriented PHP Client for Termii SMS API. Uses Termii API. Requirements PHP >= 7.2 Guzzlehttp ~6|~7 Installation Via Compo

Ilesanmi Olawale Adedotun 5 Feb 24, 2022
oursms.app client library that allows you to send SMS

Oursms laravel client https://oursms.app client library that allows you to send SMS Installation Install oursms client with composer composer requir

Khalid Mohammad 11 Aug 27, 2022
Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services

Xendit 96 Jan 6, 2023
PHP client for Kafka

A library to allow people to communicate to Kafka using plain PHP, compatible with Kafka v0.11+ (due to the way the protocol works).

Luís Cobucci 52 Dec 23, 2022
DigitalOcean API v2 client for Symfony and API Platform

DigitalOcean Bundle for Symfony and API Platform DunglasDigitalOceanBundle allows using the DigitalOcean API from your Symfony and API Platform projec

Kévin Dunglas 25 Jul 27, 2022
php 8 client for the lemon.markets api

lemon.markets php client This repository contains a php 8+ compatible client for the https://lemon.markets API. The documentation of the API can be fo

Daniel Freudenberger 4 Nov 17, 2022