PHP displays progress messages on the fly

I work in a tool in PHP that processes a lot of data and takes some time to complete. I would like the user to be updated with what is happening and the current task is being processed.

What, in your opinion, is the best way to do this? I have some ideas, but I can not decide on the most effective:

  • The old way: to execute a small part of the script and display the page to the user using Meta Redirect or the JavaScript timer to send a request to continue the script (for example, /script.php?step=2).

  • Sending AJAX requests constantly to read the server file, which PHP continues to update through fwrite ().

  • Same as above, but PHP updates the field in the database instead of saving the file.

Do any of them sound good? Any ideas?

Thank!

+3
source share
6 answers

Instead of writing a static file obtained using AJAX or in an additional database field, why not create another PHP script that simply returns the percentage of completion for the specified task. Then your page can update the progress with a very easy AJAX request to the specified PHP script.

"" script, , , " ". , "" script . , , .

UPDATE

" " script, . , .

script, , (script, ), ( , , , , , , script, ) . , 1. " ", script, . , . . , . , , . ( ), , , script. , , , .

+5

AJAX, . , - , , - .

+1

flush(), . , - - ( ).

. .

+1

2 - AJAX , PHP . . JSON , , , ..

+1

A "", - , script. , HTML-, ( , WordPress ).

, "" AJAX, , - "" .

1 2, AJAX script.php?step=1, , , script.php?step=2 ?

0

IE, , . .

0

Source: https://habr.com/ru/post/1749286/


All Articles