marcelog / PAMI

PHP Asterisk Manager Interface ( AMI ) supports synchronous command ( action )/ responses and asynchronous events using the pattern observer-listener. Supports commands with responses with multiple events. Very suitable for development of operator consoles and / or asterisk / channels / peers monitoring through SOA, etc
http://marcelog.github.com/PAMI
Apache License 2.0
402 stars 281 forks source link

PAMI ERROR HELP #165

Open jrivas111 opened 6 years ago

jrivas111 commented 6 years ago

i try to open a connection to my asterisk but i get this error:

> Fatal error: Uncaught exception 'PAMI\Client\Exception\ClientException' with message 'Error connecting to ami: No connection could be made because the target machine actively refused it. ' in C:\Apache24\htdocs\pbx\pami\vendor\marcelog\pami\src\PAMI\Client\Impl\ClientImpl.php:178 Stack trace: #0 C:\Apache24\htdocs\pbx\ami.php(17): PAMI\Client\Impl\ClientImpl->open() #1 {main} thrown in C:\Apache24\htdocs\pbx\pami\vendor\marcelog\pami\src\PAMI\Client\Impl\ClientImpl.php on line 178

this is my connection file:

<?php
require __DIR__ . '/pami/vendor/autoload.php';
use PAMI\Message\Event\EventMessage;
use PAMI\Listener\IEventListener;
$pamiClientOptions = array(
    'host' => 'host',
    'scheme' => 'tcp://',
    'port' => 5038,
    'username' => 'username',
    'secret' => 'secret',
    'connect_timeout' => 10000,
    'read_timeout' => 10000
);
use PAMI\Client\Impl\ClientImpl as PamiClient;
$pamiClient = new PamiClient($pamiClientOptions);
// Open the connection
$pamiClient->open();

// Close the connection
$pamiClient->close();

?>

this is my manager.conf file:

;
; AMI - Asterisk Manager interface
;
; FreePBX needs this to be enabled. Note that if you enable it on a different IP, you need
; to assure that this can't be reached from un-authorized hosts with the ACL settings (permit/deny).
; Also, remember to configure non-default port or IP-addresses in amportal.conf.
;
; The AMI connection is used both by the portal and the operator's panel in FreePBX.
;
; FreePBX assumes an AMI connection to localhost:5038 by default.
;
[general]
enabled =yes
port = 5038
bindaddr = 0.0.0.0
displayconnects=yes ;only effects 1.6+

[admin]
secret =051270
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate

#include manager_additional.conf
#include manager_custom.conf

NOTE: THE PBX SERVER IS AT A REMOTE LOCATION ON A DEDICATED SERVER

vforvicious commented 6 years ago

You need to change your $pamiClientOptions info: $pamiClientOptions = array( 'host' => '127.0.0.1', 'scheme' => 'tcp://', 'port' => 5038, 'username' => 'admin', 'secret' => '051270', 'connect_timeout' => 10000, 'read_timeout' => 10000 );

jrivas111 commented 6 years ago

Hello Edwin thanks for your help i did fix the problem, I have another question though

when i do: $pamiClient->registerEventListener(function (EventMessage $event) { var_dump($event); }); Every event shows instantly after its done

but when i do this: $pamiClient->registerEventListener( function (EventMessage $event) { return $event instanceof HangupEvent && var_dump($event->getCallerIDNum("CallerIDNum")) } ); When i do this, it shows the result after the loop only not while the loop, why is this?

On Mon, Apr 30, 2018, 5:30 PM Edwin Artunduaga notifications@github.com wrote:

You need to change your $pamiClientOptions info: $pamiClientOptions = array( 'host' => '127.0.0.1', 'scheme' => 'tcp://', 'port' => 5038, 'username' => 'admin', 'secret' => '051270', 'connect_timeout' => 10000, 'read_timeout' => 10000 );

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/marcelog/PAMI/issues/165#issuecomment-385534839, or mute the thread https://github.com/notifications/unsubscribe-auth/Ak-XZ40BiDgr1znyiNix0y80_wVt02oHks5tt4JxgaJpZM4TooLD .