I have a backend data management console written with CakePHP that allows a user to manage some hierarchical data. Every time a user makes a change to the data I want to regenerate a data file (JSON in this case) that’s used on the site’s frontend.
The rebuild can take some time and I’d like the backend UI to be a bit more responsive. My idea is to have the JSON rebuild take place after the new page (the “your changes have been saved” page) is rendered to the user. I’ve got some code within the afterFilter() call back in my app_controller.php, but the page doesn’t actually render in the browser until the JSON rebuild completes.
I’ve found code examples for plain-vanilla PHP that does things like send a Connection: Close HTTP header and/or uses output buffer flushing to tell the browser that the server’s done while processing continues, but these techniques don’t (as far as I can tell) work with CakePHP’s structure and its own output buffering.
What I would like is a technique that would allow me to completely render a view for the user and then, once the user has their page loaded, continue executing the JSON rebuild in the background.
I realize there may be situation/setup specific concerns that could affect things, so please let me know if you’ve got questions about my particular application.
Thanks in advance.
those cakephp queue plugins are invented for this exact purpose:
https://github.com/MSeven/cakephp_queue
they decouple the frontend from the backend services like those file generations.