PHP code example of deliverynetwork / informers-client-php

1. Go to this page and download the library: Download deliverynetwork/informers-client-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/ */

    

deliverynetwork / informers-client-php example snippets



de_once "<PATH_TO_LIBRARY>/src/FileCache.php";
;
 

try {
    $client = new \informers\client\Client(
        array(
            'site_id' => <YOUR_SITE_ID>,
            'api_key' => '<YOUR_SITE_API_KEY>',
            'api_url' => '<PLATFORM_API_URL>',
            'cache'   => new \informers\client\FileCache(
                '<PATH_TO_CACHE_DIRECTORY>',
                '<CACHE_PERIOD_IN_SECONDS>'
            )
        )
    );
    $currentUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";// current page URL
    echo $client->render($currentUrl); // rendering informer
} catch (\informers\client\ClientException $e) { /* do something if needed */ } 
 

try {
    $client = new \informers\client\Client(
        array(
            'site_id' => <YOUR_SITE_ID>,
            'api_key' => '<YOUR_SITE_API_KEY>',
            'api_url' => '<PLATFORM_API_URL>',
            'cache'   => new \informers\client\MemoryCache(             
                array(
                    'host' => 'localhost',  // Memcached  host
                    'port' => 11211,        // Memcached  port
                ), '<CACHE_PERIOD_IN_SECONDS>'
            ),
        )
    );
    $currentUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // current page URL    
    echo $client->render($currentUrl); // rendering informer
} catch (\informers\client\ClientException $e) { /* do something if needed */ } 

try {
    $client = new \informers\client\Client(
        array(
            'site_id' => <YOUR_SITE_ID>,
            'api_key' => '<YOUR_SITE_API_KEY>',
            'api_url' => '<PLATFORM_API_URL>',
            'cache'   => new \informers\client\CustomCache(
                    function($key){
                        return your_cache_get_function($key);
                    },
                    function($key, $value, $period){
                        return your_cache_set_function($key, $value, $period);
                    }, '<CACHE_PERIOD_IN_SECONDS>', '<CACHE_PREFIX>')
        )
    );
    $currentUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // current page URL    
    echo $client->render($currentUrl); // rendering informer
} catch (\informers\client\ClientException $e) { /* do something if needed */ }
json
"deliverynetwork/informers-client-php": "dev-master",