I can see from previous posts that flush() does not work and has been asked for a few times over the years. Is this something that will just never happen please ? Realtime output is something I really need, as one script “could” be running for hours at a time.
I COULD write output to a log file and tail it with an autorefresh but that is not optimal and tbh looks unprofessional.
Unless anyone else has any other ideas ? Suggestions welcome
Since we have no clue what your program is doing or exactly what you are trying to accomplish, here is a shot in the dark…
Experimented some with using ajax to run php. Not the best approach as can be resource heavy. Something like:
function myAjax() {
$.ajax({
url: 'php_script.php',
type: 'POST',
success: function(response) {
if(response != 'killprocess') {
myAjax(); // Call itself if 'killprocess' signal is not received
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Error: ' + textStatus + ' ' + errorThrown);
}
});
}
// Initial start call
myAjax();
In the ‘php_script.php’ you would need a condition which when met would echo (or output) the word ‘killprocess’.
Again, not ideal and I no longer use for long-term running of php scripts but may spark your creative mode.
Another ajax example that could work (have not tested the code) is set interval:
function myAjax() {
$.ajax({
url: 'php_script.php',
type: 'POST',
success: function(response) {
if(response == 'killprocess') {
clearInterval(myInterval); // Stop the interval if 'killprocess' signal is received
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Error: ' + textStatus + ' ' + errorThrown);
}
});
}
// Start the interval
let myInterval = setInterval(myAjax, 30000); // 30000 milliseconds is equal to 30 seconds
Another approach: start the help exe from inside exeout using the ? button. Search for “timer” or “cron”. This method may be your best bet and I would recommend reading into it.
Many thanks for that. I have not used Ajax before but will definitely have a look.
FYI, the script finds “saved game results” and uploads them to my website for anayses. People using it may have just 1 or 2 (which are about 2-3MB each on average), but others may have tens of thousands, thus it “may” be a very long running script, taking several days.
I’m surrently looking at the script uploading 1 at a time, and autorefreshing to send the next one, rinse and repeat.
flush() cannot be handled in the way we handle PHP output. This has been like this for years. However, since we are working on server apps too based on Apache, this should be possible in the future I think.
It would be good if it could. I’m currently looking at polling an output file every few seconds for any changed output, but obviously not the best solutionm as some data may be skipped from the user’s view.