Menu

add_event_handler question

2010-09-17
2013-04-29
  • Eric Wieling

    Eric Wieling - 2010-09-17

    I'm using php from the command line for testing.

    I'm trying to use add_event_handler.  I want to each event to fire off my event handler, then wait for another event.

    Here is the code I'm using.  I tried it with and without the while and sleep as well.  Does anyone have any pointers on making this work?  My background is not in OO style programming.

    require_once("/var/www/pbxmax-bin/phpagi-asmanager.php");

    $manager = new AGI_AsteriskManager();
    $result = $manager->connect();
    if($result === TRUE) {
        echo "Connection established.\n";
        $manager->add_event_handler("*", "dump_event");
        while (1 == 1) {
            sleep(1);
        }
    } else {
        echo "Connection failed.\n";
        exit;
    }

    function dump_event($ecode,$data,$server,$port) {
    echo "received event '$ecode' from $server:$port\n";
    print_r($data);
    }

     
  • Matthew Asham

    Matthew Asham - 2010-09-17

    You need to setup an eventmask to indicate what events your manager application should receive, eg:

    $manager->Events("on");

    Check phpagi-asmanager.php for more information.

     
  • Jack

    Jack - 2012-04-15

    The trick is to loop but not sleep since while sleeping you ain't receiving anything.
    Just do the following

    while(true){
        $ami->wait_response(true);
    }
    
     

Log in to post a comment.