aj-techsoul / ELECTRON-4-PHP

An easiest way to use php in electron
MIT License
202 stars 46 forks source link

Is There a Way to Flush PHP Output During Execution? #4

Closed ryanpamplin closed 6 years ago

ryanpamplin commented 6 years ago

Hello again! I've made a program with PHP that outputs progress to the browser (and updates a progress bar via JS) while it executes. It can take some time time to finish, so it's important to see the progress while it executes. I use flush() in PHP after each echo, and in the browser, it works as I intended. Using ELECTRON-4-PHP, I can only see the output after execution finishes. Do you know if there's a way to see progress as it executes using ELECTRON-4-PHP? Thank you!

aj-techsoul commented 6 years ago

please send your code, so that i can check it

aj-techsoul commented 6 years ago

Try puttng these codes in php file, and let me know if it works

@ini_set('zlib.output_compression',0);
@ini_set('implicit_flush',1);
@ob_end_clean();
ryanpamplin commented 6 years ago

I tested the following code and got it to work:

<?php $multiplier = 1; $size = 10 * $multiplier; for($i = 1; $i <= $size; $i++) { ob_flush(); flush(); echo $i."\n"; sleep(1); } ?>

It counts 1 - 10 with a 1 second delay between each in the Electron window. I don't know why it didn't work before, but it's working now. Thanks! I think this is solved for now.