I am trying to do a loading bar in php, AJAX or anything JS related can't really be used.
It works alright displaying numbers or words as it loads
echo $text;
echo str_pad('', 4096) . "
";
ob_flush();
flush();
but the problem is it displays everything in simple text.
As a result I can't add any CSS or HTML to my view through echo. I have included this header in order to make flush work and actually update my page as it loads.
header('Content-Type: text/event-stream');
The header you are using is not actually going to parse as HTML/CSS.
What you need is actually something like:
ob_implicit_flush( true );
And then normally like above
ob_start();
while (true) {
echo "Something is going on!";
ob_flush();
flush();
}
That's how I do it in most projects. Now if this doesn't work there might be some cache in your web server. I hit that issue many times. To avoid that this helps:
header( 'X-Accel-Buffering: no' );
header( 'Content-Encoding: none' );