Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read error exception #58

Closed
D0berm4n opened this issue Dec 10, 2014 · 4 comments
Closed

Read error exception #58

D0berm4n opened this issue Dec 10, 2014 · 4 comments

Comments

@D0berm4n
Copy link

Hi, Marcelo. I have "Read error" exception throws in ClientImpl->getMessages while calling from one ext to another. It happens on Win Server 2008 R2 with php 5.5.15 (Asterisk is running on my mac virtual FreePBX 6.5 (Parallels Desktop)).

It throws when DialEvent recieved.

Here is my code

use PAMI\Message\Event\LinkEvent;
use PAMI\Message\Event\DialEvent;
use PAMI\Message\Event\HangupEvent;
use PAMI\Message\Event\BridgeEvent;
use PAMI\Message\Event\NewAccountCodeEvent;

$adapter = new AsteriskAdapter(
    $CONFIG['asterisk_host'],
    $CONFIG['asterisk_protocol'],
    $CONFIG['asterisk_port'],
    $CONFIG['asterisk_login'],
    $CONFIG['asterisk_pass']);

if (isset($CONFIG['asterisk_host'], $CONFIG['asterisk_protocol'], $CONFIG['asterisk_port'], $CONFIG['asterisk_login'], $CONFIG['asterisk_pass'])){

    while(true){

        AsteriskAdapter::log("[Asterisk Manager Interface (AMI) Connection]");

        if($adapter->connect()){

            try{
                AsteriskAdapter::log("Successfully conected to {$CONFIG['asterisk_host']}:{$CONFIG['asterisk_port']} as {$CONFIG['asterisk_login']}");

                $adapter->registerCallListener(function(DialEvent $event) use ($adapter){
                    $number = $adapter->getNumber($event->getDestination());
                    $callerId = $event->getCallerIDNum();
                    AsteriskAdapter::log("EVENT: Dial Line: {$number} CallerId: $callerId");
                    AsteriskAdapter::logdb(AsteriskAdapter::EVENTTYPE_DIAL, $number, $callerId);
                });

                $adapter->registerLinkListener(function(LinkEvent $event) use ($adapter){
                    $number = $event->getCallerID2();
                    $callerId = $event->getCallerID1();
                    $channel = $event->getChannel2();
                    $filename = $number . "-" . $callerId . "-" . date("Y-m-d-H-i-s");
                    $adapter->startChannelRecord($channel, $filename);
                    AsteriskAdapter::log("EVENT: Link Line: {$number} CallerId: $callerId");
                    AsteriskAdapter::logdb(AsteriskAdapter::EVENT_TYPE_LINK, $number, $callerId, $filename);
                });

                $adapter->registerBridgeListener(function(BridgeEvent $event) use ($adapter){
                    $number = $event->getCallerID2();
                    $callerId = $event->getCallerID1();
                    $channel = $event->getChannel2();
                    $filename = $number . "-" . $callerId . "-" . date("Y-m-d-H-i-s");
                    $adapter->startChannelRecord($channel, $filename);
                    AsteriskAdapter::log("EVENT: Bridge Line: {$number} CallerId: $callerId");
                    AsteriskAdapter::logdb(AsteriskAdapter::EVENT_TYPE_LINK, $number, $callerId, $filename);
                });

                $adapter->registerHangupListener(function(HangupEvent $event) use ($adapter){
                    $number = $adapter->getNumber($event->getChannel());
                    $callerId = null;
                    AsteriskAdapter::log("EVENT: Hangup Line: {$number} CallerId: $callerId");
                    AsteriskAdapter::logdb(AsteriskAdapter::EVENT_TYPE_HANGUP, $number, $callerId);
                });

                $adapter->registerNewAccountCodeListener("CLICKTODIAL", function(NewAccountCodeEvent $event) use ($adapter){
                    $channel = $event->getChannel();
                    $callerId = $adapter->getNumber($channel);
                    $filename = "CLICKTOCALL-" . $callerId . "-" . date("Y-m-d-H-i-s");
                    $adapter->startChannelRecord($channel, $filename);
                    AsteriskAdapter::log("EVENT: NewAccountCode CallerId: $callerId");
                    AsteriskAdapter::logdb(AsteriskAdapter::EVENT_TYPE_NEWACCOUNTCODE, "", $callerId, $filename);
                });

                while(true){
                    $adapter->client->process();
                }

            }catch (Exception $e){
                AsteriskAdapter::log("Exception: " . $e->getMessage());
            }

        }else{
            $errorMsg = $adapter->getConnectionError();
            AsteriskAdapter::log("ERROR: Can't connect to AMI {$errorMsg}");
            usleep(10000000);
        }
    }
}else{
    AsteriskAdapter::log("ERROR: Configuration vars not set");
    echo("ERROR: Configuration vars not set");
}

This script is running in command line and writes events to MySQL db.
When I start script on my Mac from terminal everything is good. It log all events to db.

@jacobkiers
Copy link
Contributor

Hi, a few follow-up questions:

  • Which version of Asterisk are you running (you mention the FreePBX version, but that apparently differs from the Asterisk version)?
  • Do you have the exact error message and the stack trace for the Exception?
  • Do you have a list of all the Events as they are sent from AMI (so the actual text as received from Asterisk)?

I think these are necessary to effectively help you debug this issue.

@D0berm4n
Copy link
Author

Hi, thanks, I solved problem.
If it will help somebody the reason was in FreePBX server and host on which I run my logger script are in different subnets and Asterisk close socket connection because of timeout.
I added line

writetimeout=10000

to manager.conf in context of my manager user and it solve the problem.

here is issue on asterisk website https://issues.asterisk.org/jira/browse/ASTERISK-19603

@jacobkiers
Copy link
Contributor

Great to know that your problem is solved. Thank you for the explanation.

PS. You can close the issue now.

@marcelog
Copy link
Owner

Hey guys, I'm closing this issue then. Thanks for discussing! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants