r/PHPhelp • u/MrCaspan • Oct 26 '25
PHP needs to update when we hook is triggered
I have a dashboard that shows me open and active tickets. These tickets are from freshdesk and I am pulling them into a dashboard VIA their API. I don't want to hammer their API like every 30 seconds just to see if there is any new data and also doing an auto refresh would be crappy if you're halfway down a page and it auto refreshes. it's just not a great idea. I do have the capability on freshdesk to specify if any update to a ticket happens it can send a trigger to a webhook URL. it doesn't have to send any data but it can. I want to use this as a trigger to send a notification to refresh the page. I cannot seem to figure out how to get the web page to actively monitor a file for modified etc . I have tried SSE but my web server is using a version of pgp with a front end that cashes all output until the script ends before it outputs it all and it can't be changed.. I don't want to use websockets as that seems overkill. there has to be a simpler way to be able to push a notification from the server to the web browser so I can trigger my tickets have been updated function.. it won't just cause the page to instantly refresh as again that'll be annoying if you're in the middle of editing a ticket and the page auto refreshes.. it'll just pop up a notification on the screen that tickets have been updated and if it ignored for a minute it will refresh the page.
any ideas of a very easy simple way to do this?
6
u/martinbean Oct 26 '25
…and yet that’s the solution.
Literally the use case for websockets.
2
u/cursingcucumber Oct 26 '25
What makes you think the whole page needs to refresh with AJAX? Polling is actually the easiest low-tech solution here and if done every 30s, it won't cause any noticeable load on any server 😅
I honestly think you're overthinking this and instead you can just try to implement it and go from there. Dare to make mistakes and learn from them. Only thinking about possible mistakes and never trying anything is just silly and won't get you anywhere.
7
u/Bubbly-Nectarine6662 Oct 26 '25
Easiest way to accomplish this is to set up an AJAX conversation with very little data, like only replying the last update timestamp. Only if the replied last update ts is younger than the cached one, you can refresh the whole page. Use the hasFocus() object to check if you’re disrupting an update.
1
u/UbiquitousTool Oct 31 '25
Websockets feel like overkill but they are kinda the standard for this now.
If you want to avoid them, the classic solution is AJAX long polling. It's a bit of a middle ground.
Basically:
It's less resource-intensive than polling every few seconds and avoids the SSE caching issue you're hitting.
1
u/MateusAzevedo Oct 27 '25
Ideally, your dashboard won't be tied to Freshdesk API, ie, you have a local copy of the tickets so refreshing the page won't call their API. This allows for a simple approach to reach your goal: webhook will only update the database records (effectively a background task), while your frontend can use long polling to check if there's any update. You can either return "true/false" and show a notification, or return the new/updated tickets and update individual items in the page with JS.
If having a local database isn't possible or feasible, then I can see 2 possible solutions:
1- The webhook will only save when the last update occurred. Frontend then query for that info and, based on a local variable, check if a refresh is needed.
2- Pusshing data from the server to the client is only possible with SSE, websockets or Mercure (similar to websockets).