Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an activity timeout configuration option #241

Merged
merged 7 commits into from
Aug 21, 2024
Merged

Add an activity timeout configuration option #241

merged 7 commits into from
Aug 21, 2024

Conversation

zeke0816
Copy link
Contributor

The reason why I am proposing this change is because I actually need this in my own application, where there is one reverb app that I need to ping constantly (every 5 seconds). Plus, I frankly do not understand why there is a ping_interval configuration if it is not used at all except for checking whether you are active or not. In fact, what defines being active is something we should all set for ourselves based on our business rules when developing apps and this rule may vary from application to application, like in my case.

As for breaking existing features, the one thing I would point out is that the default setting in the configurations is 60 seconds, whilst in this branch it was hardcoded to 30 seconds. So, if people were expecting the app to ping every 30 seconds, this should remain unchanged. Therefore, I also changed the configuration file to default to 30 such that the behavior does not change for those who did not set the environment value.

I believe this makes building web applications better because it makes sense out of the configuration and it is an important feature of real-time applications. Being able to change this on an application-basis and quickly via a configuration file and environment variables is a huge advantage for developers, in my honest opinion.

As per tests, I obviously tested this locally and my application indeed started pinging every 5 seconds rather than 30, but I do not really see how to provide a test for this here. This is, after all, my first contribution to any open source repository, and I am not used to it. In any case, I could provide a screenshot showing the results later in comments.

I deeply apologize to everyone if this change is not the intended behavior and I am just talking nonsense, but it really fixes my personal problem and is what I needed. I will understand if this PR is not approved. And, by the way, I would even suggest changing the variable name from $pingInterval to $activityTimeout, since it makes more sense for the app. Even for the Laravel\Reverb\Contracts\Connection::isActive() function.

Thank you for an amazing solution to WebSockets!

The current `activity_timeout` option when establishing a connection was hardcoded to 30 seconds, but sometimes we need our application to ping at a different rate. This value should be configured through the proper config file using the `ping_interval` option which takes `REVERB_APP_PING_INTERVAL` environment variable or 60 by default.

This update takes the value which is loaded onto the `Application` class and is available through the `Connection` class, making this an easy fix.
This change makes sure that all future applications that re-publish the configuration keep the original 30 second value instead of the 60 second default configuration. All applications that modified this value in their environment file should not be affected.
@joedixon joedixon self-assigned this Aug 16, 2024
@joedixon
Copy link
Collaborator

I think it makes sense to send a configurable activity_timeout as part of the connection_established event rather than hard coding it. However, I'm not sure it makes sense to reuse ping_interval for this since they have different purposes.

I don't think I'm against adapting this PR to introduce a new activity_timeout config option.

What do you think?

Screenshot 2024-08-16 at 08 47 01

@zeke0816
Copy link
Contributor Author

I think that's a good idea finding common ground, I was not sure about the usage of ping_interval and I definitely did not find the resource you shared here, so I will update the PR accordingly!

…stead of `ping_interval` to separate the concerns and accomplish the same result.
@zeke0816
Copy link
Contributor Author

Oops, need to pass some tests, I'll fix this now!

…finition. Using `30` as the default value as this was the original value in the package.
@zeke0816 zeke0816 changed the title The ping interval configuration does not affect the activity timeout. Add an activity timeout configuration option. Aug 16, 2024
@zeke0816 zeke0816 changed the title Add an activity timeout configuration option. Add an activity timeout configuration option Aug 16, 2024
@taylorotwell taylorotwell marked this pull request as draft August 16, 2024 18:21
@taylorotwell
Copy link
Member

Drafting this pending review from @joedixon

@driesvints driesvints requested a review from joedixon August 19, 2024 07:44
Copy link
Collaborator

@joedixon joedixon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a minor tweak to set the default value to prevent a breaking change, but otherwise this looks good, thanks!

@joedixon joedixon marked this pull request as ready for review August 19, 2024 12:06
@taylorotwell taylorotwell merged commit d0e83cc into laravel:main Aug 21, 2024
9 checks passed
@zeke0816 zeke0816 deleted the patch-1 branch August 21, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants