[Asterisk-Users] Manager API Help

Jeremy Wadhams jwadhams1 at yahoo.com
Mon Apr 10 11:01:47 MST 2006


This is the code I wrote to do that job, without getting into the full phpagi:


function readManagerResponse($resp, $lookFor) {
    $value_start = strpos($resp, $lookFor) + strlen($lookFor); 
    $value_stop = strpos($resp, "\r\n", $value_start); 
    if (strpos($resp, $lookFor) === FALSE ){ 
        echo "ERROR: readManagerResponse() didn't find $lookFor in $resp<br>"; return FALSE;
    } else {
        $hold = substr($resp, $value_start, $value_stop - $value_start); return $hold;
    }
}

function goodResponse($resp){ 
    $stat = readManagerResponse($resp, "Response: ");
    if ($stat === FALSE) {}
    return ($stat == "Success");
}


=== open a connection to Manager on $fp, and get logged in====

fputs ($fp, "Action: DBget\r\n");
fputs ($fp, "Family: webdialer\r\n");
fputs ($fp, "Key: $thingImLookingFor\r\n\r\n");
sleep(2) ;
$resp = null;
       do {
         $line = fgets($manager, 4096);
         $resp .= $line;
        } while (($line != "\r\n") && ($line));
if (goodResponse($resp)) { // If the key exists, get the value
    $resp = getFromManager($fp);
    $callercontext = readManagerResponse($resp,"Val: ");
    echo "Using database value $callercontext as context.<br>\r\n";
} else {
    echo "No database entry, or couldn't authenticate to the AstDB.<br>\r\n"; 
    echo "Caller will instead use $defaultContext context.<br>\r\n"; 
    $callercontext = $defaultContext;
}

Hope that helps,
--JW

----- Original Message ----
From: Darren Ellis <darren at ieworks.net>
To: Asterisk Users Mailing List - Non-Commercial Discussion <asterisk-users at lists.digium.com>
Sent: Sunday, April 9, 2006 7:23:18 PM
Subject: [Asterisk-Users] Manager API Help

Hi All,

Could someone send me a code frag on how to get a record from the 
asterisk database into a PHP variable via the Manager API?

I can issue calls, etc. from Manager.  But I'm not comprehending how to 
manipulate database variables.

Thanks much.

Darren Ellis

_______________________________________________
--Bandwidth and Colocation provided by Easynews.com --

Asterisk-Users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20060410/aafe77d1/attachment.htm


More information about the asterisk-users mailing list