1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'General PHP and MySQL Discussions' started by cclaerhout, Mar 24, 2013.

  1. cclaerhout

    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:
    $i 0;
    foreach (
    $words as $word)
    $i 50)
    $i 0;
  2. Jeremy

    Jeremy Well-Known Member

    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.
    cclaerhout likes this.
  3. cclaerhout

    cclaerhout Well-Known Member

    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.
  4. cclaerhout

    cclaerhout Well-Known Member

    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.
  5. HenrikHansen

    HenrikHansen Well-Known Member

    I am sooooo tired of this message. I see it all the times when I edit me templates. I hope it can be solved
  6. cclaerhout

    cclaerhout Well-Known Member

    In my case this message is totally normal since I'm asking too much. But in your case, just ask your host to increase the script execution time limit.
    HenrikHansen likes this.
  7. cclaerhout

    cclaerhout Well-Known Member

    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:
    1) 'chinese_words_loop': http://pastebin.com/8idmAgLn
    2) 'chinese_words_loop_js': http://pastebin.com/N8mqfPfA

    Example (in the controller admin):
    Adam Howard likes this.

Share This Page