1. Go to this page and download the library: Download tmsolution/phpari 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/ */
tmsolution / phpari example snippets
echo "Starting ARI Connection\n";
$ariConnector = new phpari();
echo "Active Channels: " . json_encode($ariConnector->channels()->channel_list()) . "\n";
echo "Ending ARI Connection\n";
try {
$conn = new phpari("hello-world"); //create new object
$app = new applications($conn);
$result=$app->applications_list();
if ((!$result) && (count($result)))
throw new Exception("phpari error occured", 503);
echo json_encode($result);
exit(0);
} catch (Exception $e) {
echo "Error: " . $conn->lasterror. "\n";
echo "Trace: " . $conn->lasttrace. "\n";
}
class BasicStasisApplication
{
private $ariEndpoint;
private $stasisClient;
private $stasisLoop;
private $phpariObject;
private $stasisChannelID;
private $dtmfSequence = "";
public $stasisLogger;
public function __construct($appname = NULL)
{
try {
if (is_null($appname))
throw new Exception("[" . __FILE__ . ":" . __LINE__ . "] Stasis application name must be defined!", 500);
$this->phpariObject = new phpari($appname);
$this->ariEndpoint = $this->phpariObject->ariEndpoint;
$this->stasisClient = $this->phpariObject->stasisClient;
$this->stasisLoop = $this->phpariObject->stasisLoop;
$this->stasisLogger = $this->phpariObject->stasisLogger;
$this->stasisEvents = $this->phpariObject->stasisEvents;
} catch (Exception $e) {
echo $e->getMessage();
exit(99);
}
}
public function StasisAppConnectionHandlers()
{
try {
$this->stasisClient->on("request", function ($headers) {
$this->stasisLogger->notice("Request received!");
});
$this->stasisClient->on("handshake", function () {
$this->stasisLogger->notice("Handshake received!");
});
$this->stasisClient->on("message", function ($message) {
$event = json_decode($message->getData());
$this->stasisLogger->notice('Received event: ' . $event->type);
$this->stasisEvents->emit($event->type, array($event));
});
} catch (Exception $e) {
echo $e->getMessage();
exit(99);
}
}
public function execute()
{
try {
$this->stasisClient->open();
$this->stasisLoop->run();
} catch (Exception $e) {
echo $e->getMessage();
exit(99);
}
}
$basicAriClient = new BasicStasisApplication("hello-world");
$basicAriClient->stasisLogger->info("Starting Stasis Program... Waiting for handshake...");
$basicAriClient->StasisAppEventHandler();
$basicAriClient->stasisLogger->info("Connecting... Waiting for handshake...");
$basicAriClient->execute();
[root@ari agi-bin]# php test.php
Starting ARI Connection
Active Channels: []
Ending ARI Connection
$ php ApplicationList.php
Error: Failed connect to 178.62.XXX.XXX:8080; No error
Trace: #0 C:\Users\nirsi_000\Documents\phpari\vendor\educoder\pest\Pest.php(128): Pest->doRequest(Resource id #60)
#1 C:\Users\nirsi_000\Documents\phpari\src\interfaces\applications.php(58): Pest->get('/applications')
#2 C:\Users\nirsi_000\Documents\phpari\examples\ApplicationList.php(33): applications->applications_list()
#3 {main}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.