[Asterisk-Users] PHP and ASterisk Manager

Matthew Boehm mboehm at cytelcom.com
Tue Sep 6 11:49:29 MST 2005


Anton Krall wrote:
> Guys, is anybody using PHP sockets to connect to the Manager and send
> command like "show voicemail users" for example or any other?
> 
> My question is, how to parse the return info in a way that can be shown back
> to the user via web (discard all the manager responses not needed)?

Use preg_match() to match the lines you want the user to see on the website.

$socket = fsockopen("localhost","5038", $errno, $errstr, 30);

if(!$socket) {
         print "No socket";
	exit();
}

fputs($socket, "Action: Login\r\n");
fputs($socket, "Events: Off\r\n");
fputs($socket, "UserName: bleh\r\n");
fputs($socket, "Secret: bleh\r\n\r\n");

fputs($socket, "Action: Command\r\n");
fputs($socket, "Command: show channels\r\n\r\n");

fputs($socket, "Action: Logoff\r\n\r\n");

while(!feof($socket)) {
         $buff = fgets($socket,1024);
         if(preg_match("/SIP\/.*/", $buff)) {
		print "I found a SIP call";
         }
}




More information about the asterisk-users mailing list