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

Home Page:http://marcelog.github.com/PAMI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Read Timeout

black187 opened this issue · comments

Hello,

I'm trying to run the quickstart example, but I allways get - read timeout after a minute of loading of example.php.

I'm working on Centos 5.6, with PHP 5.3 and log4php installed... I see that the script tries to connect to AMI, but no success:

Asterisk cli:

== Client from 127.0.0.1, failed to authenticate in 30 seconds

log.log:

*----------
2012-02-27 19:58:24,001 [DEBUG] Pami.ClientImpl: ------ Sending: ------
action: Login
actionid: 1330369073.3835
username: test
secret: test123


2012-02-27 20:02:26,001 [DEBUG] Pami.ClientImpl: ------ Sending: ------
action: Login
actionid: 1330369315.1347
username: test
secret: test123

----------*

example.php (changed parts):

date_default_timezone_set("Europe/Berlin");
set_include_path('/var/www/html/test/PAMI/log4php');
// Setup include path.
ini_set(
'include_path',
implode(
PATH_SEPARATOR,
array(
implode(DIRECTORY_SEPARATOR, array('..', '..', '..', 'src', 'mg')),
ini_get('include_path'),
)
)
);
.
.
.
.
try
{
$options = array(
'log4php.properties' => realpath(DIR) . DIRECTORY_SEPARATOR . 'log4php.properties',
'host' => 'localhost',
'port' => '5038',
'username' => 'test',
'secret' => 'test123',
'connect_timeout' => 10000,
'read_timeout' => 10000,
'scheme' => 'tcp://' // try tls://
);

Manager.conf has the correct entry's for user test.

How can I debug, where is the problem with the too long loading?

Edit: Just tried with scheme => tls, and it works OK now... My mistake

Hmm, it looks like I have to create a certificate for tls connection (with asterisk).

Don't need such security, so the problem in the first post still alive - if scheme is tcp, there is a timeout on example.php script.

Hi! Thanks for your feedback.

Unfortunately, I cant reproduce it. I'm going to need some more information. Can you post the values for the following entries in manager.conf?

enabled
bindaddr
port
sslenable
sslbindport
sslbindaddr

Thanks,

Hi,

the whole directory of PAMI (from github) is in the attachment.

This is my Asterisk manager.conf setting:

[general]
webenabled=yes
enabled = yes
port = 5038
bindaddr = 0.0.0.0
displayconnects=yes

[test]
secret=test123
permit=0.0.0.0/0.0.0.0
read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write =
system,call,agent,log,verbose,user,config,command,reporting,originate

On Mon, Feb 27, 2012 at 8:49 PM, Marcelo Gornstein <
reply@reply.github.com

wrote:

Hi! Thanks for your feedback.

Unfortunately, I cant reproduce it. I'm going to need some more
information. Can you post the values for the following entries in
manager.conf?

enabled
bindaddr
port
sslenable
sslbindport
sslbindaddr

Thanks,


Reply to this email directly or view it on GitHub:
#27 (comment)

The problem is at

$a->open();

This is the part of the code, where it all goes bad (long execution time).
I've traced the loopback interface with wireshark, and saw, that the script
is communication with Asterisk on port 5038 (a lot of messages), but it
seems they cannot understand eachother...

On Tue, Feb 28, 2012 at 9:13 AM, Leky Shakur black187@gmail.com wrote:

Hi,

the whole directory of PAMI (from github) is in the attachment.

This is my Asterisk manager.conf setting:

[general]
webenabled=yes
enabled = yes
port = 5038
bindaddr = 0.0.0.0
displayconnects=yes

[test]
secret=test123
permit=0.0.0.0/0.0.0.0
read =
system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write =
system,call,agent,log,verbose,user,config,command,reporting,originate

On Mon, Feb 27, 2012 at 8:49 PM, Marcelo Gornstein <
reply@reply.github.com

wrote:

Hi! Thanks for your feedback.

Unfortunately, I cant reproduce it. I'm going to need some more
information. Can you post the values for the following entries in
manager.conf?

enabled
bindaddr
port
sslenable
sslbindport
sslbindaddr

Thanks,


Reply to this email directly or view it on GitHub:
#27 (comment)

The problem lies within "public function open()" in ClientImpl.php, at the
" $id = $this->getLine();" - this getLine function is not responding, as I
checked what does it do, I get this:

protected function getLine()
{
    return stream_get_line($this->_socket, 1024, Message::EOL);
}

Is it possible that it never gets to end of line (EOL)?

On Tue, Feb 28, 2012 at 10:17 AM, Leky Shakur black187@gmail.com wrote:

The problem is at

$a->open();

This is the part of the code, where it all goes bad (long execution time).
I've traced the loopback interface with wireshark, and saw, that the script
is communication with Asterisk on port 5038 (a lot of messages), but it
seems they cannot understand eachother...

On Tue, Feb 28, 2012 at 9:13 AM, Leky Shakur black187@gmail.com wrote:

Hi,

the whole directory of PAMI (from github) is in the attachment.

This is my Asterisk manager.conf setting:

[general]
webenabled=yes
enabled = yes
port = 5038
bindaddr = 0.0.0.0
displayconnects=yes

[test]
secret=test123
permit=0.0.0.0/0.0.0.0
read =
system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write =
system,call,agent,log,verbose,user,config,command,reporting,originate

On Mon, Feb 27, 2012 at 8:49 PM, Marcelo Gornstein <
reply@reply.github.com

wrote:

Hi! Thanks for your feedback.

Unfortunately, I cant reproduce it. I'm going to need some more
information. Can you post the values for the following entries in
manager.conf?

enabled
bindaddr
port
sslenable
sslbindport
sslbindaddr

Thanks,


Reply to this email directly or view it on GitHub:
#27 (comment)

I'm sorry, but it I've just tested it with asterisk 1.4, 1.6, and 1.8 (the same example shipped with pami) and works ok, both tls and tcp.

Can you provide access to your asterisk so I can test it there? If not, can you send what you have captured with wireshark? are you absolutely sure you disabled ssl in your manager.conf and are using tcp:// ? because you said earlier that it worked with tls, the read routine is exactly the same. So if it works for you with tls, it should work with tcp too.

Also, can you paste your complete source code? If you are running the pami example, paste the command line options you're using. Like: php example.php 127.0.0.1 5038 test test 10000 10000

thanks,

According to what we spoke via email, I'm leaving these comments for future reference:

  • The tests on your system were ok, running example.php from my own box and connecting to your asterisk box. Your localhost tests were not.
  • With TLS you got it working, and not with TCP, which is weird since both use the same code to work (php streams).
  • I still cant reproduce the problem either in 1.4, 1.6, and 1.8, with tls and tcp.
  • After digging some more, you said it worked by uncommenting the call to stream_set_timeout() in ClientImpl. This call was commented out because the reading routine in send() already controls the read timeout, so it wasnt necessary anymore.
  • So even with that call uncommented, I think that if there was a bug in the send() method, it should have been triggered anyway. This makes me think about some other difference in the default timeout value for the socket in our php installations.

So I'm closing this issue now, but will keep an eye on this. Thanks again for the feedback and the effort :)

Hi,
I have downloded pami-1.72 version and keep it in /usr/share/php/ ..
and changed example.php..but i don't know how to run this php file via browser..plz..kindly do the needful