0
ignore_user_abort();
set_time_limit(0);
$interval=60;
$flag=true;
file_put_contents("log.log","Starts \r\n");

while($flag){

  date_default_timezone_set("America/New_York");
  $mytime=date("y/m/d h:i:sa");   
  $file = fopen("C:/work/testData/test.txt","r"); 
  $myfile=fread($file,filesize("C:/work/testData/test.txt"));

  if(stristr($myfile,"Finish writing tables")){
    file_put_contents("log.log","Finished! Ready To Send Email $mytime         \r\n",FILE_APPEND);                                
    $flag=false;    
   }else{
    file_put_contents("log.log","Still Running $mytime $myfile     \r\n",FILE_APPEND);          
   }   

fclose($file);
sleep($interval);
}

I want the code read test.txt every 60 seconds, once test.txt includes string "Finish writing tables",then stop. Test.txt file is updated by other application in the same time. And I find that in else {}, every 60 seconds it didnt read the updated test.txt file, still read the old test.txt

Thank you very much

Jason Z
  • 265
  • 1
  • 6
  • 12
  • 2
    Better approach in this situation would be cron script which would be run once a minute and then only check for some condition. – insanebits Mar 05 '15 at 15:05
  • but I run this code on windows – Jason Z Mar 05 '15 at 15:11
  • 1
    Windows has scheduled tasks which may be used in a similar way as linux crontab http://stackoverflow.com/questions/9894804/use-php-to-set-cron-jobs-in-windows – insanebits Mar 05 '15 at 15:13

1 Answers1

0

problem solved.

Add clearstatcache() after fclose()

Jason Z
  • 265
  • 1
  • 6
  • 12