title: Bash infinite loop sleep having strange behavior (NGINX/PHP-FPM/PGSQL)
body: <p>I'm not sure it should be in stackoverflow or serverfault. I post here because it may be a programming problem.</p>
  
  <p>I have this infinite loop:</p>
  
  <pre><code>#!/bin/bash
  
  MESSAGE="XXX0"
  RESULT=`curl "http://somepage.php?thread=0"`
  
  while :
  do
  
  
      if [[ "$RESULT" == "DONE" ]] 
      then
          RESULT=`curl "http://somepage.php?thread=0"`
      elif [[ "$RESULT" == "NONE" ]] 
      then
          sleep 5
          RESULT=`curl "http://somepage.php?thread=0"`
      else
          printf "%s %s\n" "$(date --rfc-3339='seconds'): ELSE1-" "$RESULT"   &gt;&gt; /var/log/XXX/loopXXX-`date --rfc-3339='date'`
          sleep 5
          RESULT=`curl "http://somepage.php?thread=0"`
  
          if [[ "$RESULT" == "DONE" ]] 
          then
              RESULT=`curl "http://jsomepage.php?thread=0"`
          elif [[ "$RESULT" == "NONE" ]] 
          then
              sleep 5
              RESULT=`curl "http://somepage.php?thread=0"`
          else
              printf "STOP"
              break
          fi
      fi
  
  done
  </code></pre>
  
  <p>I have 3 loops doing the same job and requesting thread 0 to 2. In the DBtable the PHP page request, there is a column thread. So the three loops query the same table (read/write) but never the same lines.</p>
  
  <p>The problem I experience is that in some nights (almost no activity), one loop doesn't request a page for several hours (I checked in NGINX access log). This only happen sometimes and the server is way more powerfull than needed yet.</p>
  
  <p>Is there problems using infinite loop with curl? In total I have around 10 loops (different pages/tables) but they have a 10s sleep instead of 5s.</p>
  
  <p>Is there a problem in my script with memory/curl? Have you ever experienced something similar?</p>
  
  <p>THanks!</p>