定制 palzin-apm/palzin-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

palzin-apm/palzin-php

最新稳定版本:24.8.1

Composer 安装命令:

composer require palzin-apm/palzin-php

包简介

Monitoring Package

README 文档

README

Latest Release Total Downloads (custom server) Packagist License GitHub last commit GitHub Release Date

Simple code execution monitoring and bug reporting for PHP developers.

Requirements

  • PHP >= 7.2.0

Install

Install the latest version of our package by:

composer require palzin-apm/palzin-php

Use

To start sending data to Palzin APM you need an INGESTION Key to create an instance of the Configuration class. You can obtain PALZIN_APM_INGESTION_KEY creating a new project in your Palzin APM dashboard.

use Palzin\Palzin;
use Palzin\Configuration;

$configuration = new Configuration('YOUR_PALZIN_APM_INGESTION_KEY');
$palzin = new Palzin($configuration);

All start with a transaction. Transaction represent an execution cycle and it can contains one or hundred of segments:

// Start an execution cycle with a transaction
$palzin->startTransaction($_SERVER['PATH_INFO']);

Use addSegment method to monitor a code block in your transaction:

$result = $palzin->addSegment(function ($segment) {
    // Do something here...
	return "Hello World!";
}, 'my-process');

echo $result; // this will print "Hello World!"

Palzin APM will monitor your code execution in real time and keep alerting you if something goes wrong.

Custom Transport

You can also set up custom transport class to transfer monitoring data from your server to Palzin APM in a personalized way.

The transport class needs to implement \Palzin\Transports\TransportInterface:

class CustomTransport implements \Palzin\Transports\TransportInterface
{
    protected $configuration;

    protected $queue = [];

    public function __constructor($configuration)
    {
        $this->configuration = $configuration;
    }

    public function addEntry(\Palzin\Models\Arrayable $entry)
    {
        // Add an \Palzin\Models\Arrayable entry in the queue.
        $this->queue[] = $entry;
    }

    public function flush()
    {
        // Performs data transfer.
        $handle = curl_init('https://www.palzin.app');
        curl_setopt($handle, CURLOPT_POST, 1);
        curl_setopt($handle, CURLOPT_HTTPHEADER, [
            'X-Palzin-Key: xxxxxxxxxxxx',
            'Content-Type: application/json',
            'Accept: application/json',
        ]);
        curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($this->queue));
        curl_exec($handle);
        curl_close($handle);
    }
}

Then you can set the new transport in the Palzin instance using a callback the will receive the current configuration state as parameter.

$palzin->setTransport(function ($configuration) {
    return new CustomTransport($configuration);
});

LICENSE

This package is licensed under the MIT license.

统计信息

  • 总下载量: 204
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-10