PHP loop blocking the rest of the code to execute [closed]

You could try:

[CODE]  [SOME MORE CODE]  [BIG LOOP]

But if “some more code” depends on “big loop”, then you have a problem. Here are a few ideas:

  • Optimize your loop. It is possible you have some kind of gross inefficiency in your loop.
  • Do less work. Maybe you don’t need to process the entire big loop, and can do less processing.
  • Cache your results. If the same loop is being executed frequently and producing the same results, maybe you can save the results in a file/APC/memcached ?
  • Use AJAX. Load a page without the data from the big loop, and then have that page use AJAX to load the data you need. You can present a page with a nice ‘please wait while we get your data’ message/icon/whatever.

Leave a Comment