Automatically perform Logoff during the close call
lisachenko opened this issue · comments
On a moderate usage of PAMI we can see errors like this:
PAMI\Client\Exception\ClientException: "Error reading''true"
at ~/vendor_composer/marcelog/pami/src/mg/PAMI/Client/Impl/ClientImpl.php line 234
On the Asterisk side there will be errors:
ERROR[22439] utils.c: fwrite() returned error: Broken pipe
ERROR[22439] utils.c: fwrite() returned error: Broken pipe
I found an email with step-by-step guide how to solve this:
> AMI is a *two-way* protocol. You mustn't just fire in a bunch of commands
> and close the socket!
>
> The reason Asterisk reports the fwrite() error is because you have closed
> the socket before it had a chance to send you the responses.
>
> What you need to do is this:
>
> 1. Connect to the AMI port.
> 2. Read the one-line greeting message that Asterisk sends you. It will tell
> you the version of the protocol (which might be of interest if you
> wanted
> to be compatible with different versions of Asterisk).
> 3. Send the Login action with username, secret and terminating blank line.
> 4. Read the response lines from Asterisk until it gives you a blank line.
> 5. Send whatever command you want it to do, and go back to step 4.
> 6. When you have done the commands you want, send the Logoff action.
> 7. *** READ THE RESPONSE TO THE LOGOFF
> 8. Close the socket.
So, the issue is with Logoff
method. I want to propose to add automatic sending of Logoff
packet during the $pamiClient->close()
call like with Login
action in the $pamiClient->open()
. This will prevent server from strange errors.
If we do loggoff operation inside close we probably should be aware of #57
Can be related to the #35