PHP Classes

File: sample.php

Recommend this page to a friend!
  Classes of Joshua hatfield   floAPI   sample.php   Download  
File: sample.php
Role: Example script
Content type: text/plain
Description: An example script
Class: floAPI
Interface to control Asterisk PABX program
Author: By
Last change:
Date: 19 years ago
Size: 1,859 bytes
 

Contents

Class file image Download
<pre><?
/***************************************************************************
 * Original floAPI copyright (C) 2005 by Joshua Hatfield. *
 * *
 * In order to use any part of this floAPI Class, you must comply with *
 * the license in 'license.doc'. In particular, you may not remove this *
 * copyright notice. *
 * *
 * Much time and thought has gone into this software and you are *
 * benefitting. We hope that you share your changes too. What goes *
 * around, comes around. *
 ***************************************************************************/

// Include the file.
include("floAPI.php");

// Create the object.
$sampleapi = new floAPI("username", "password", "127.0.0.1");

// Start collecting events.
$sampleapi->events_toggle("ON");

// Run a test command (sip show peers).
echo($sampleapi->request("COMMAND", array("COMMAND" => "sip show peers")));

// Wait up to twenty seconds for an event to happen, checking
// once each second.
$t = 0;
while(!(
$events_found = $sampleapi->events_check()) && $t < 20){
   
$t++;
   
sleep(1);
}

// How many did we find in one check?
echo("-- Events found: $events_found\r\n\r\n");

// Display collected events.
while($event = $sampleapi->events_shift()) {
    echo(
"<b>$event</b>");
}

// Close the connection.
$sampleapi->close();

echo(
"LOGGED OUT!\r\n\r\n");

echo(
"-- Additional events: ".$sampleapi->events_check());

// Display any events since the first check till logout.
while($event = $sampleapi->events_shift()) {
    echo(
"<b>$event</b>");
}
?></pre>