I want to print chunked data in php like parrot.live
But i am unable to achieve it 🙁
here is my Nginx conf code
location /animation {
try_files $uri /animation.php;
fastcgi_keep_conn on;
add_header Content-Type text/plain;
add_header Cache-Control no-cache;
add_header Connection keep-alive;
add_header Transfer-Encoding chunked;
}
and here is my php code
` <?php
// Set appropriate headers for streaming data
header('Content-Type: text/plain; charset=utf-8');
header('Cache-Control: no-cache');
header('Connection: keep-alive');
header('Transfer-Encoding: chunked');
// Function to flush output to the client
function flush_output($str) {
echo $str . "\n"; // Output a chunk of data followed by a newline
ob_flush(); // Flush the output buffer
flush(); // Ensure output is sent to the client
usleep(500000); // Delay to control animation speed (500ms)
}
// Your ASCII animation frames (example)
$frames = [
"⠋ Loading...",
"⠙ Loading...",
"⠹ Loading...",
"⠸ Loading...",
"⠼ Loading...",
"⠴ Loading...",
"⠦ Loading...",
"⠧ Loading...",
];
// Loop through frames and stream each one
foreach ($frames as $frame) {
flush_output($frame);
}
?> `