web-push-php icon indicating copy to clipboard operation
web-push-php copied to clipboard

Pass a custom variable to flush()

Open fx1234 opened this issue 3 years ago • 5 comments

We are using the following simple code to flush the Queue:

foreach( $webPush->flush() as $report ){ .... }

The problem is, we need our own variables (the UserID) inside the loop. Is there a way to pass custom variables into the loop? Maybe so that it is available in $report

fx1234 avatar Oct 13 '22 23:10 fx1234

any ideas?

tgves avatar Jan 31 '24 22:01 tgves

I'm unsure I understand the underlying problem here. If you are able to access your own variables when calling flush, why can't you use them inside the for loop?

I know this is old, but the issue is not closed so apparently still an issue

Gugu7264 avatar Jun 18 '24 09:06 Gugu7264

I think it was about connecting our internal user IDs directly with the push notifications without having to get this information from the database within the loop for each notification.

With a large number of outgoing notifications, this would mean a lot of extra database queries inside the loop

I don't have direct access to the code right now and because it was a while ago, I'm not 100% sure whether the problem was more extensive. But basically it was about making our own information available for each notification inside the loop

fx1234 avatar Jun 18 '24 17:06 fx1234

Okay, I think I get what you mean because I'm encountering the same issue. I end up using the endpoint to find the user 😁

Gugu7264 avatar Jun 18 '24 20:06 Gugu7264

If you send a large number (thousands) of notifications at the same time, it is a big overhead if you have to get the data from the database for each user. It would therefore be better if you had a way to have the required data available directly in $report

fx1234 avatar Jun 18 '24 22:06 fx1234