web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.7k stars 295 forks source link

Pass a custom variable to flush() #358

Open fx1234 opened 1 year ago

fx1234 commented 1 year ago

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

tgves commented 8 months ago

any ideas?

Gugu7264 commented 3 months ago

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

fx1234 commented 3 months ago

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

Gugu7264 commented 3 months ago

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 😁

fx1234 commented 3 months ago

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