PHP code example of hamkaran / pami

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

    

hamkaran / pami example snippets




AMI\Client\Impl\ClientImpl;
use PAMI\Message\Event\CdrEvent;

$client = new ClientImpl([
    'host' => '127.0.0.1',
    'scheme' => 'tcp://',
    'port' => 5038,
    'username' => 'ami-user',
    'secret' => 'ami-secret',
    'connect_timeout' => 10,
    'read_timeout' => 10,
]);

$client->registerEventListener(
    function (CdrEvent $event): void {
        printf(
            "Call %s: %s -> %s\n",
            $event->getUniqueID(),
            $event->getSource(),
            $event->getDestination()
        );
    },
    fn ($event): bool => $event instanceof CdrEvent
);

$client->open();

try {
    while (true) {
        $client->process();
    }
} finally {
    $client->close();
}

$listenerId = $client->registerEventListener(
    [$listener, 'handle'],
    fn ($event): bool => $event instanceof CdrEvent
);

// Remove the listener when it is no longer needed.
$client->unregisterEventListener($listenerId);