xmppo / xmpp-php

PHP client library for XMPP (Jabber) protocol
https://github.com/xmppo/xmpp-php
MIT License
45 stars 23 forks source link

all works, but very slow #9

Closed hedgehed closed 4 years ago

hedgehed commented 4 years ago

Hi Hello My sequence of connecting and sending a message takes about 10 seconds, how can this be accelerated? My code is ` $logger = new Logger('xmpp'); $logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));

    $options
        ->setHost($hostname)
        ->setPort($port)
        ->setUsername($adminUsername)
        ->setPassword($adminPassword)
        ->setLogger(new my_logger());

    $client = new XmppClient($options);

    $client->connect();
    $client->iq->getRoster();
    $client->message->send('Hello world', 'vovan@мщмфтюсщь');
    $client->disconnect();

` launched on same server with ejabberd.

Thanks !

hedgehed commented 4 years ago

I found the problem in the module norgul/xmpp-php/src/Socket.php uses fgets($this->connection) with a timeout of 1 second

here is solution idea https://stackoverflow.com/questions/9356152/non-blocking-on-stdin-in-php-cli

Norgul commented 4 years ago

Hello @hedgehed

the slowness issue was already discussed here, and apparently timeout which is set to 1 in Socket.php imposes a 1s timeout, not setting the max waiting period (which I initially thought).

You can speed it up by using a 250ms timeout instead (stream_set_timeout third parameter is microseconds so you can pass 250000 there and use 0 as second parameter).

This is something I have started working on but am currently a bit busy so I can't. If you find a nice solution feel free to make a PR.

Thank you

Norgul commented 4 years ago

Hello @hedgehed, I have made the improvements and published as new patch version. You can try it out. I am closing the issue as resolved. Thanks