SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I set timeout for a loop iteration

    Hello,

    I have a while loop that fetches data from a mysql table and in each iteration it does many different things using many functions and classes.

    The problem is that sometimes it gets stuck (maybe trying to open or read a file), so is there any way to skip the current iteration if it gets stuck by setting a timeout?

    Can I set a timeout for a while loop so that if at any iteration that timeout limit is reached it'd continue to the next iteration?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can set a time limit on execution of the entire page request, but not for an individual block of code. If it's stuck, it's not going to reach any code that checks if some time limit has been reached.

    Solve the problem instead of trying to work around it.

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Grand Rapids, MI
    Posts
    1,284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Read the table into an array beforehand, thus instead of doing 100+ DB calls you do only 1.

  4. #4
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should figure out what function is getting stuck and focus on that.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •