0

I have a long PHP event script (~1 min long) that gets fired off from the front-end. In my script, I currently just echo to the console thats running the server, but I'd like to forward those echos to the client side as well. These echos are just to show the current process/step the script so that users can see the progress rather than just empty wait.

Some ideas that I had were to use laravel-echo with Pusher or store those echo messages using Laravel Session and just Poll every 5 or so seconds on the front end.

I'd prefer not to rely on a 3rd party service like Pusher (for the long run) and the second option seems inefficient and hard coded.

Any suggestions or approaches?

yeehuboi
  • 175
  • 1
  • 5
  • We used Laravel-Echo (in our Vue.js SPA) and broadcast messages to it via Pusher, as a way to get up and running quickly. Longer term we may look into swapping Pusher for a self-managed Socket.io and Redis solution, but it works well for now. And we avoid any inefficient polling... – Rich Sep 05 '18 at 21:46
  • Polling is simple, and not really that hard on the server, so unless performance is already an issue, i would probably do that. You will need to use some other persistence mechanism though (eg database table), since the background task will not be using a web session, or you could go full 1990's and run the script in an iframe with `ob_flush()`. – Jason bamber Sep 05 '18 at 21:55
  • You can even setup your own laravel echo server with redis instead of using pusher. It still works with the pusher driver (laravel perspective) https://github.com/tlaverdure/laravel-echo-server - doing this you should also think about doing the long running request in a queue so that you don't keep open the connection for 1 minute or even get a timeout. – Frnak Sep 06 '18 at 12:25

0 Answers0