PHP code example of cristianovalenca / pami

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

    

cristianovalenca / pami example snippets




use PAMI\Client\Impl\ClientImpl as PamiClient;

$options = array(
    'host'            => '127.0.0.1',
    'scheme'          => 'tcp://',
    'port'            => 5038,
    'username'        => 'admin',
    'secret'          => 'secret',
    'connect_timeout' => 10,
    'read_timeout'    => 10,
);

$client = new PamiClient($options);
$client->open();

// Register a listener (a Closure, an [object, method] pair, or an IEventListener):
$client->registerEventListener(function ($event) {
    echo get_class($event), PHP_EOL;
});

// Send an action and read the response.
use PAMI\Message\Action\PingAction;
$response = $client->send(new PingAction());

// Keep processing events (e.g. inside your own loop):
$client->process();

$client->close();

use PAMI\Message\Event\DialEvent;

$client->registerEventListener(
    array($listener, 'handleDialStart'),
    function ($event) {
        return $event instanceof DialEvent && $event->getSubEvent() === 'Begin';
    }
);

$client->setLogger($logger);