title: Scheduled Task duplicate on php.exe
body: <p><b>From</b> further investigation I have found there is an exact issue on how long certain instances of the task run for. most successfully run in a few seconds, yet a few consecutive tasks are running up to an hour (then stopped by the manager). At this point any information about Windows scheduled task life cycle would be appreciated </p>
  
  <hr>
  
  <p>I have a php file which needs to be called every 10 minutes.
  The php file deals with new database entries that are updated on the call.</p>
  
  <p>The file is executed via a scheduled task call to php.exe with -f argument (with said file after)</p>
  
  <p>The task is performed as expected, and runs without fail.
  However, I have noticed two problems since its initial run.
  <br/>
  <br/><b>1st</b>, I had a <code>file_put_contents</code> on a log file which added a 'Schedule Task()' plus the current time, line every time the task ran. <br>For the first few days this ran fine, but it wasn't until one evening when command failed to execute as the log file had filled up (a .txt at just under 1GB).
  I checked, and the logfile read as:</p>
  
  <pre><code>Schedule Task() 2014-10-10 18:00:00.000
  Schedule Task() 2014-10-10 18:00:00.000
  Schedule Task() 2014-10-10 18:00:00.000
  (repeated for 1000s of lines, but still with milliseconds time incrementing every 500 lines or so)
  </code></pre>
  
  <p>Where I'd expect it to display as:</p>
  
  <pre><code>Scheduled Task () 2014-10-10 18:00:00.000
  Scheduled Task () 2014-10-10 18:10:00.000
  Scheduled Task () 2014-10-10 18:20:00.000
  </code></pre>
  
  <p>This suggests that the process got stuck on that line, as the milliseconds for 500 lines were equal. </p>
  
  <p>To resolve this, I moved the <code>file_put_contents</code> line after an IF statement to ensure the line would only be written to the log file when new records were in the database.</p>
  
  <p>The problem never happened again.<br />
  <br /> <b>2nd</b>, However, 3 weeks from the first scheduled task (today) I notice that the scheduled task's history is filled with errors, at a 10 minute incremental rate. 
  The error code given is that of 'Duplicate instances running'. (Which is correct as I have set the option to not run instances if one is already in progress)</p>
  
  <p>This, suggests that the Scheduled Task manager is executing the action multiple times (multiple processes).</p>
  
  <p>At this stage, I'm not sure wether it is a fault by the scheduled task, or if it is a code issue where I am not correctly ending the file. Has anyone had a similar issue?</p>
  
  <p><b>Update</b>
  <br>From looking into the scheduled task amanbager logs, I can see that there is an issue with the task running longer than 1 hour (see image)</p>
  
  <p><img src="https://i.stack.imgur.com/5VLyw.png" alt="enter image description here"></p>
  
  <p>The call is running every 10 minutes however the task run (red line) is not escaping correctly. </p>