Perl waits until the time-consuming task is done before showing the output. (And tThere are no more print commands after the time-consuming task by the way.)
I thought I'd get clever and put the time-consuming task into an external file, but that doesn't help:
print "Content-type:text/html\n\n $output"; `perl timeConsumingTask.pl`; # OR do('timeConsumingTask.pl'); # OR system('timeConsumingTask.pl');
There's no difference between these. Perl still waits until the external script has run before showing the output. (By the way, I can't try 'exec', because my webhost has disabled it for security reasons.)
I thought I had a clever solution, by redirecting the user to a new page before running the time-consuming task, but that doesn't help either:
Same deal. The time-consuming task runs first before showing the output.
My final idea is to set a flag in a text file along with a list of data to process, and have a cron job run every minute, checking for the flagged file, and then running if it finds the flagged file. But this is really inelegant. I'd rather not have a cron job running every single minute of every single day, and even if it does, it doesn't process the data as quickly as a regular script would. (The data takes about six seconds to process, and when the user goes to the next page, the processed data might not be ready yet. But please please please, let's not get sidetracked about that. Please trust me that the issue above is exactly as I've described it.)