PHP code example of palzin-apm / palzin-php

1. Go to this page and download the library: Download palzin-apm/palzin-php 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/ */

    

palzin-apm / palzin-php example snippets


use Palzin\Palzin;
use Palzin\Configuration;

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

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

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

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

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);
    }
}

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