1. Go to this page and download the library: Download anders/ami-react 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/ */
$loop = \React\EventLoop\Factory::create();
$factory = new Factory($loop);
$factory = new Factory($loop, $connector);
$factory->createClient('user:secret@localhost')->then(
function (Client $client) {
// client connected and authenticated
},
function (Exception $e) {
// an error occured while trying to connect or authorize client
}
);
$client->on('event', function (Event $event) {
// process an incoming AMI event (see below)
});
$client->on('close', function () {
// the connection to the AMI just closed
});
$client->on('error', function (Exception $e) {
// and error has just been detected, the connection will terminate...
});
$sender = new ActionSender($client);
$sender->ping()->then(function (Response $response) {
// response received for ping action
});
$sender->ping()->then(
function (Response $response) {
// response received for ping action
},
function (Exception $e) {
// an error occured while executing the action
if ($e instanceof ErrorException) {
// we received a valid error response (such as authorization error)
$response = $e->getResponse();
} else {
// we did not receive a valid response (likely a transport issue)
}
}
});