John Davidson

server sent events - Best way to communicate the status of long running PHP-script to other PHP-Script for SSE

0 comments
Message:


I have a long running PHP-Script, which handles a big XML-file.



  1. user does XML upload to upload.php

  2. upload.php running few minutes

  3. Browser creates new EventSource("status.php") to ask the current status


So what is the best practised way to let status.php know what upload.php is doing?


Plan was to write a log-file in upload.php and let status.php look if something new is inside the log-file.


But for sure there is other ways to let upload.php and status.php communicate together, or not?



My Answer:
'update.php') to listen for updates_

One way to communicate the status of the long running PHP script to another PHP script for Server Sent Events (SSE) is to use a shared database or file to store the status information.

Here is a general outline of how you can implement this:

1. In your long running PHP script, update the status information to a shared database or file at regular intervals. For example, you can update a "status" field in a database table with the current progress of the script.

2. In your update.php script, create an EventSource object to listen for updates from the shared database or file. You can use AJAX to periodically check for updates and send them to the client using Server Sent Events.

3. When the client receives an update from the update.php script, you can display the status information to the user in real-time.

By using a shared database or file to store and retrieve the status information, you can effectively communicate the progress of the long running PHP script to other PHP scripts using Server Sent Events.

Rate this post

3 of 5 based on 2347 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us