title: PHP script stops working suddenly without reason
body: <p>I'm running a BIG PHP script, it might take a <i>full day</i> to finish its job,<br>
  this script grabs data from MySQL database and use it with curl to test stuff.. it does it with about <i>40,000</i> records..<br>
  So to make it run on background for as long as it needs, i used the terminal to execute it.. in the PHP script itself it has those settings to make sure it runs as long as possible until it finishes :</p>
  
  <pre><code>set_time_limit(0); // run without timeout limit
  </code></pre>
  
  <p>and because i execute it from another separated PHP script i use this function</p>
  
  <pre><code>ignore_user_abort(1); // ignore my abort
  </code></pre>
  
  <p>because executing it directly from the command line, it will give me two choices.. <br>1 ) to wait till the script finishes<br> 2 ) cancel the whole process</p>
  
  <p>and after searching, there was an article that gives me a third choice and its to run it in background for longest possible <b>by</b> creating an external PHP script to excute the main BIG PHP script in background using this function:<br></p>
  
  <pre><code>exec("php bigfile.php");
  </code></pre>
  
  <p>that means i can open this external page normally from a browser and exit it without worry since <code>ignore_user_abort</code> will keep it running in background.. <b>That's still not the problem</b></p>
  
  <p>the problem is.. after an unknown period, the script stops its job.. <i>how do i know ?</i> I told it to write in an external file the current date time on each record it works on, so i refresh everytime to that external page to see if it stopped updating,</p>
  
  <p>after an unknown period it actually stops for no reason, the script has nothing that says stop or anything.. and if anything wrong happened, i told it to skip the record ( nothing wrong happens tho, they all work in the same line, if one works then all should work )</p>
  
  <p>However my main doubts are in the following :</p>
  
  <ul>
  <li>Apache has a timeout that kills it</li>
  <li>That was not the proper way to execute PHP script in background</li>
  <li>There is a timeout somewhere, whether in PHP or Apache or (<b>MySQL</b> !?)<br>
       that's where my biggest doubt goes.. <b>MySQL</b>, Would it ever stop giving records to the PHP loop from <code>while</code> ? Would it crash the whole script if an error occurred ? Does it has any timeout at anything that crashes the whole script ? </li>
  </ul>
  
  <p>If none of those could apply to it, Is there any way to log what is exactly going on the script now ? Or why would it crash ? any detailed way to log everything ?</p>
  
  <p><hr>
  <b>UPDATE</b>:</p>
  
  <p>I FOUND this in <code>messages</code> file in <code>/var/log/</code> :</p>
  
  <pre><code>Dec 29 16:29:56 i0sa shutdown[5609]: shutting down for system halt
  Dec 29 16:30:14 i0sa exiting on signal 15
  Dec 29 16:30:28 i0sa syslogd 1.5.0#6: restart.
  Dec 29 16:50:28 i0sa -- MARK --
              .....
  Dec 29 18:50:31 i0sa -- MARK --
  Dec 29 19:02:36 i0sa shutdown[3641]: shutting down for system halt
  Dec 29 19:03:11 i0sa exiting on signal 15
  Dec 29 19:03:48 i0sa syslogd 1.5.0#6: restart.
  </code></pre>
  
  <p>it says for system halt.. I'll try to make sure that this could be it in the future crashes and match times, COULD this be causing it ? and why ? <code>memory_limit</code> is 128M while i have <code>2GB</code> of server memory ram, could this be it ?</p>
  
  <p>P.S.: I restarted the server several times manually.. But this one says shutdown and halt ?</p>