How can PHP developers address issues with automatic scrolling of output in different browsers, especially for long-running scripts?

When outputting long-running scripts in PHP, browsers may automatically scroll to the bottom of the page, making it difficult for users to view the output in real-time. To address this issue, developers can use JavaScript to disable the automatic scrolling behavior in the browser.

<?php
// PHP code to output long-running script with disabled automatic scrolling

// Disable automatic scrolling using JavaScript
echo '<script>window.scrollTo(0,document.body.scrollHeight);</script>';

// Output your long-running script here
for ($i = 0; $i < 1000; $i++) {
    echo $i . '<br>';
    flush(); // Flush the output buffer
    ob_flush(); // Flush the PHP buffer
    sleep(1); // Simulate a delay
}
?>