phpnats icon indicating copy to clipboard operation
phpnats copied to clipboard

Disconnecting after 1 minute

Open donifer opened this issue 6 years ago • 11 comments

I'm having the same issue as: https://stackoverflow.com/questions/48744861/php-nats-client-disconnects-after-some-idle-time

After connecting, receiving few messages and having some 30 secs idle time, it gets disconnect itself without any interruption. However my Node.js client is working good with the same NATS server.

Not sure what I'm missing.

donifer avatar Dec 20 '18 03:12 donifer

+1

fizzka avatar Jan 08 '19 19:01 fizzka

what version of gnatsd are you running?

byrnedo avatar Jan 09 '19 08:01 byrnedo

latest,

docker run --rm nats -v
nats-server version 1.3.0

fizzka avatar Jan 09 '19 09:01 fizzka

looks like that default_stream_timeout (60s) used while connecting

fizzka avatar Jan 09 '19 09:01 fizzka

This is indeed caused by the default_stream_timeout. You can change the timeout with:

$client = new \Nats\Connection();
$client->connect(300); // Or even $client->connect(PHP_INT_MAX);

Or:

ini_set('default_stream_timeout', 300); // Or even ini_set('default_stream_timeout', PHP_INT_MAX);

$client = new \Nats\Connection();
$client->connect();

Large stream timeouts (above 999) are currently not handled properly. PR #132 contains changes to allow larger stream timeouts. I have just created PR #135 with some additional changes to improve the way stream timeouts are handled.

timsmid avatar Jan 12 '19 19:01 timsmid

@timsmid could you create a fork with all your PR merged and added to composer registry? Since there is no active maintaining of the library

rockfridrich avatar Feb 22 '19 05:02 rockfridrich

@timsmid could you create a fork with all your PR merged and added to composer registry? Since there is no active maintaining of the library

You will probably be better of setting up a repository / package yourself. Unfortunately, I have currently no intent to actively maintain or support this library. My fork with the applied timeout changes is publicly available at https://github.com/timsmid/phpnats/tree/develop.

If you have any further questions though, feel free to ask.

timsmid avatar Feb 24 '19 15:02 timsmid

@timsmid how to pull your repository with composer?

rockfridrich avatar Mar 06 '19 03:03 rockfridrich

@timsmid how to pull your repository with composer?

You might be able to reference it directly in your composer.json file, although I am not entirely sure about the syntax. You can probably use the repositories key as described in the Composer documentation (https://getcomposer.org/doc/05-repositories.md).

Another alternative is forking my repository and creating a Packagist package yourself. Then you can use your own package in your composer.json file. That would probably be the sanest route, as you would be in full control of the code.

timsmid avatar Mar 06 '19 19:03 timsmid

use like this: $client->connect(-1);

youpuyewolong avatar Aug 31 '22 09:08 youpuyewolong

use like this: $client->connect(-1);

thanks! seems, it works, but it is slightly ambiguous to permanently write this in queue consumers, right?

fizzka avatar Aug 31 '22 10:08 fizzka