SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict melchiorus's Avatar
    Join Date
    Jun 2004
    Location
    Indiana
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Infinite Looping

    I've been working on a way to constantly check the database for changes and have made an infinite while(true) loop. I would do a socket server but my host doesn't allow such actions.

    My loop is just fine, but the problem lies in the rest of the site when the loop is running. If I try and load up another part of the server, say phpMyAdmin, it will just sit there and not connect at all. I have a feeling it has something to do with max connections but there is only one connection running and I have a very high connection number.

    I'm not quite sure of what I should do here. I like my infinite loop but I don't like the fact it's causing the rest of my server to go haywire. Is there an alternative to my methods or is there perhaps some way I can get the rest of my server working correctly?
    -Melchior (Stephen Craton)

  2. #2
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd think a cron running a command line PHP script would be a better choice. If you don't have that kind of access to your server, maybe build something to do the check into all/many pages on your site, but have logic so the call does not occur every access to control the frequency.
    Last edited by arborint; Sep 19, 2004 at 18:11.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Melbourne
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try putting a sleep call into the loop, otherwise it'll try and execute as fast as it can, which will hog your cpu cycles.

  4. #4
    SitePoint Addict melchiorus's Avatar
    Join Date
    Jun 2004
    Location
    Indiana
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    Firstly, I would do a CRON, but I'm somewhat streaming out content, since this is for a chat, so setting up a cron would not work.

    Secondly, I have a sleep command in the loop which is why I don't know what it's not working. I have tried various numbers in the sleep from 1 to 10.
    -Melchior (Stephen Craton)


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
  •