问题
I'm using LOAD DATA INFILE
to import 11M records and then the script continues with other operations. The import takes 10 minutes by which time the browser has given up (after 3 minutes) and I don't see the progress of the subsequent operations. Is there a way to output something to the browser periodically while this time consuming query is running. Phpmyadmin seems to do something like this and the browser doesn't time out.
回答1:
Check out flush() (http://php.net/manual/en/function.flush.php) or ob_flush() (http://www.php.net/manual/en/function.ob-flush.php).
Basically you generate your output (current status in this case) normally then force the server to output what is currently in the buffer.
If your operation is taking 10 minutes you will likely need to use set_time_limit($seconds) (http://php.net/manual/en/function.set-time-limit.php), be careful you don't just set it to some big amount in case the page does hang.
If you want to output status every 10% (1 minute) you could reset the timeout for 2 minutes after each update has been flushed. This way your script will timeout if it goes beyond expected time running.
来源:https://stackoverflow.com/questions/8264324/periodically-output-to-browser-on-long-operation