I wrote an ajax function to call a script which creates a zip archive of about 500 files. There is a loop to add the files to the archive. That loop contains a filecounter. Now I want to update the status at the browser every 50 files. But the php script will send the whole output when the script ends and the zip file is complete.
The principle is quite similar to the following post: Echo 'string' while every long loop iteration (flush() not working)
(Except to solution is not working on my server)
I found a lot of possible solutions, but nothing works...
I tried it with the flush/ob_flush method (ob_implicit_flush as well), but flush the content don't work for me. I played a litte with the server configuration but it didn't help. Also all the examples didn't work. Maybe a server problem.
I tried SSE but the next response succeed also after the script ends.
I tried to use WebSocket but I had some problems with the handshake.
The code may look like this
$filecounter = 0;
foreach ($files as $file) {
// add $file to zip archive
$filecounter++;
if ($filecounter % 50 == 0) {
echo $filecounter;
}
}
Are there other options to get this working? Or how i get the code 'flushed'?
Thanks for your help!