How to know how many user is connected

Home » Asterisk Users » How to know how many user is connected
Asterisk Users 5 Comments

Hi List,

I want to know how many manager is connected into asterisk server. I have
made simple file but I don’t have any idea how to get information back from
Asterisk CLI

< ?php $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 30);
if (!$socket)
{
$done=0;
} else {
fputs($socket, “Action: Loginrn”);
fputs($socket, “UserName: rootrn”);
fputs($socket, “Secret: energyrnrn”);
fputs($socket, “Action: Commandrn”);
fputs($socket, “Command: manager show connectedrn”);
$done=1;
}

?>

Now how to get information into this PHP file….

5 thoughts on - How to know how many user is connected

  • hi:
    please refer this:
    http://www.voip-info.org/wiki/view/Asterisk+manager+Example:+PHP
    and check the manager.conf, make sure the accounts in managers.conf matchs the managers displayed.

    Best regards,
    James.zhu
    Doing asterisk/PRI/ss7/dahdi, linux, asterisk cards, gateway(fxs/fxo/pri< ->SIP).
    website: http://www.voipviews.com

    I’m not a php expert, but seems your php script is incomplete/ you are sending to socket (fputs) but note receiving anything(fgets) :See this page will help you. From: asterisk-users-bounces@lists.digium.com [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of virendra bhati
    Sent: Wednesday, August 24, 2011 6:16 PM
    I want to know how many manager is connected into asterisk server. I have made simple file but I don’t have any idea how to get information back from Asterisk CLI

    < ?php $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 30);
    if (!$socket)
    {
    $done=0;
    } else {
    fputs($socket, “Action: Loginrn”);
    fputs($socket, “UserName: rootrn”);
    fputs($socket, “Secret: energyrnrn”);
    fputs($socket, “Action: Commandrn”);
    fputs($socket, “Command: manager show connectedrn”);
    $done=1;
    }

    ?>

    Now how to get information into this PHP file….

  • Hi List,

    Thanks for guide me. Yes I know that CLI command , My motive is to get
    information into Php that’s why I am finding the solution.

    Ahmad Sir, You are right I forget to get information back from CLI to Php
    file. Thanks for provide the help link.I will revert back after testing my
    code with your guidance

    On Thu, Aug 25, 2011 at 12:21 PM, DHAVAL INDRODIYA

  • What I understood: you need to disconnect the AMI socket.

    1) I want to disconnect connected manager into Asterisk. Is it possible ?
    ß Close the $socket after you get the response.

    What I understood: you need to maintain the socket until some button is
    pressed to stop AMI
    2) I want to maintain this socket connection until we disconnect it from web
    page. ß Close the $socket on particular action from web-page. This one’s
    tricky btw maintain a while loop and break loop on a condition toggled by
    web-page)

    See php section for other examples.

    http://www.voip-info.org/wiki/view/Asterisk+manager+Examples

    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of virendra bhati
    Sent: Thursday, August 25, 2011 4:02 PM

    Hi List,

    Thanks now I am able to get all values from asterisk CLI but I want 2 more
    things .

    1) I want to disconnect connected manager into Asterisk. Is it possible ?
    2) I want to maintain this socket connection until we disconnect it from web
    page.

    Hi List,

    Thanks for guide me. Yes I know that CLI command , My motive is to get
    information into Php that’s why I am finding the solution.

    Ahmad Sir, You are right I forget to get information back from CLI to Php
    file. Thanks for provide the help link.I will revert back after testing my
    code with your guidance

    On Thu, Aug 25, 2011 at 12:21 PM, DHAVAL INDRODIYA
    wrote:

    Hi
    You can use simple cli command
    Manager show connected

    the managers displayed.
    gateway(fxs/fxo/pri< ->SIP).
    sending to socket (fputs) but note receiving anything(fgets) :

    http://www.voip-info.org/wiki/view/Asterisk+manager+Example:+PHP will help
    you.

    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of virendra bhati
    made simple file but I don’t have any idea how to get information back from
    Asterisk CLI

  • Just realized that maybe you’re talking about disconnecting any other
    AMI/manger connected user from another manager connection…hhmmm… I don’t
    think so. Check AMI commands from asterisk wiki. If not, you may need system
    command in your AMI connection to close some other socket.

    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Gohar Ahmed
    Sent: Thursday, August 25, 2011 4:25 PM

    What I understood: you need to disconnect the AMI socket.

    1) I want to disconnect connected manager into Asterisk. Is it possible ?
    ß Close the $socket after you get the response.

    What I understood: you need to maintain the socket until some button is
    pressed to stop AMI
    2) I want to maintain this socket connection until we disconnect it from web
    page. ß Close the $socket on particular action from web-page. This one’s
    tricky btw maintain a while loop and break loop on a condition toggled by
    web-page)

    See php section for other examples.

    http://www.voip-info.org/wiki/view/Asterisk+manager+Examples

    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of virendra bhati
    Sent: Thursday, August 25, 2011 4:02 PM

    Hi List,

    Thanks now I am able to get all values from asterisk CLI but I want 2 more
    things .

    1) I want to disconnect connected manager into Asterisk. Is it possible ?
    2) I want to maintain this socket connection until we disconnect it from web
    page.

    Hi List,

    Thanks for guide me. Yes I know that CLI command , My motive is to get
    information into Php that’s why I am finding the solution.

    Ahmad Sir, You are right I forget to get information back from CLI to Php
    file. Thanks for provide the help link.I will revert back after testing my
    code with your guidance

    On Thu, Aug 25, 2011 at 12:21 PM, DHAVAL INDRODIYA
    wrote:

    Hi
    You can use simple cli command
    Manager show connected

    the managers displayed.
    gateway(fxs/fxo/pri< ->SIP).
    sending to socket (fputs) but note receiving anything(fgets) :

    http://www.voip-info.org/wiki/view/Asterisk+manager+Example:+PHP will help
    you.

    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of virendra bhati
    made simple file but I don’t have any idea how to get information back from
    Asterisk CLI

  • Hi Ahmed,

    Just realized that maybe you’re talking about disconnecting any other
    AMI/manger connected user from another manager connection…hhmmm… I don’t
    think so. Check AMI commands from asterisk wiki. If not, you may need system
    command in your AMI connection to close some other socket
    *
    Yes I was looking for this 🙂
    *Please tell me how to close other socket from current sockets.

    one more thing in my case it may be possible that
    root 127.0.0.1 may be more then one then how to close them individually? *
    *