Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Sleep()函数不使用';行不通_Php_Sleep_Fopen_Fread - Fatal编程技术网

PHP Sleep()函数不使用';行不通

PHP Sleep()函数不使用';行不通,php,sleep,fopen,fread,Php,Sleep,Fopen,Fread,这段php代码循环遍历一个txt文件,检查它是否包含一些字符串。txt文件由另一个应用程序提供 当我运行这段代码时,我会首先得到txt字符串,60秒后我会得到相同的txt字符串。文件正在持续写入,因此内容应该已更改 为什么每60秒输出一个相同的字符串? ignore_user_abort(); set_time_limit(0); $interval=60; $flag=true; file_put_contents("log.log","Starts \r\n"); while($flag){

这段php代码循环遍历一个txt文件,检查它是否包含一些字符串。txt文件由另一个应用程序提供

当我运行这段代码时,我会首先得到txt字符串,60秒后我会得到相同的txt字符串。文件正在持续写入,因此内容应该已更改

为什么每60秒输出一个相同的字符串?

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);
}

您希望这段代码做什么?(模糊地)描述的行为似乎与code.BTW匹配,还有文件_get_contents(),您应该缩进希望其他人阅读的代码。我希望代码每60秒读取一次test.txt,一旦test.txt包含字符串“Finish writing tables”。Test.txt文件正在同时更新其内容。我发现,在else{}中,每隔60秒,它没有读取更新的test.txt文件,将文本澄清成段落,删除不必要的感谢