How to avoid "The server did not respond in time" message with big loops and callbacks?

cclaerhout

Well-known member
I have a basic question, but I can't find a way to avoid the server to display this error: "The server did not respond in time". I've tried to use the sleep command in the loop, but it doesn't work. Since I'm on local with Xamp I can modify the php configuration, but I'm just curious to know what is the proper way to avoid this (a short example would be nice).

Here's the code I've used:
PHP:
$i = 0;
foreach ($words as $word)
{
    //Code
    
    $i++;
    if($i > 50)
    {
        sleep(40);
        $i = 0;
    }
}
 
Using sleep actually delays the response even longer. We utilize the idea of lazy-loaders at work, where you AJAX in more results (or handle it via front end after page-load). Best bet is to optimize to decrease response time.
 
Using sleep actually delays the response even longer. We utilize the idea of lazy-loaders at work, where you AJAX in more results (or handle it via front end after page-load). Best bet is to optimize to decrease response time.
So the sleep commands doesn't reinit the server...

The other option I may try is to use nested foreach. That sounds stupid but I've got two controller actions. One is to reindex some threads (based on some Chinese flashcards adding or edition some threads, prefixes & message content). This one takes all flashcards from the db and process in a big foreach. It's with this one the error message occurs. But with the other, which is to restore the same flaschards from an xml file is divided in several foreach (just to follow the structure of the xml): books (level 1 => book) => lessons (level 2 => lesson ) => words (level 3 => word). And with this one, it's working.

I will try this week to replicate the xml loop pattern to the db to see if it solves the problem.
 
My previous message was a none-sense. It was working because I've used set_time_limit(0); in the loop. I guess I will have no other choice that to make a queue list.
 
Just for reference if someone needs it, here's a generic function I wrote for my script to divide and dispatch arrays (inside the db). You will have to update it for your needs of course (especially the names). It certainly can be improved, but it's working.

Controller Admin:
http://pastebin.com/00duG3yJ
Model:
http://pastebin.com/3e6YMXGf
Templates:
1) 'chinese_words_loop': http://pastebin.com/8idmAgLn
2) 'chinese_words_loop_js': http://pastebin.com/N8mqfPfA


Example (in the controller admin):
http://pastebin.com/hGtZK6bZ
 
Back
Top Bottom