web-push-php
web-push-php copied to clipboard
Get subscription from report (in case of error)
NOTE: Please test in a least two browsers (i.e. Chrome and Firefox). This helps with diagnosing problems quicker.
Please confirm the following:
- [x] I have read the README entirely
- [x] I have verified in the issues that my problem hasn't already been resolved
Setup
Please provide the following details, the more info you can provide the better.
- Operating System: Linux
- PHP Version: 8.1.8
- web-push-php Version: Good question, were to find it? (It's not in the source)
Please check that you have installed and enabled these PHP extensions :
- [x] gmp
- [x] mbstring
- [x] curl
- [x] openssl
Please select any browsers that you are experiencing problems with:
- [ ] Chrome
- [ ] Firefox
- [ ] Firefox for Mobile
- [ ] Opera for Android
- [ ] Samsung Internet Browser
- [x] Other
Server side, general concept.
Problem
When iterating over reports after $webPush->flush() how to find which subscription the report belongs to? I'd like to clean any 410 Gone subscriptions.
Expected
I would expect something like $report->getSubscription() to be able to get the subscription from the report and handle errors.
Features Used
- [x] VAPID Support
- [x] Sending with Payload
Example / Reproduce Case
/**
* Check sent results
* @var MessageSentReport $report
*/
foreach ($webPush->flush() as $report) {
$endpoint = $report->getRequest()->getUri()->__toString();
if (!$report->isSuccess()) {
// Here you want to handle 410 Gone errors by disabling the subscription (e.g. in the dbase)
$sub = $report->getSubscription();
handleExpiredSubscription($sub);
}
}
Other
Please put any remaining notes here.