より大きなクエリ フォーム mysql を含むページがあり、結果が 2MB を超える可能性があります。サーバーに十分なメモリがないため (クエリ時間を高速化するために mysql のメモリを調整する必要があります)、memcached をあきらめました。代わりに、それは txt ファイルです。
このような状況でファイルをロックするにはどうすればよいですか? ファイルがロックされている場合は読み取りのみ、ファイルがロックされていない場合は、最初に書き込み、次に読み取ります。ありがとう。
if((time()-filemtime(filename)) > 60){
//mysql_query; query time less than 1.5 seconds
if(ex_lock){ // if file is lock, only read
file_get_contents($filename);
}else{ // if file isn't lock, first write then read
file_put_contents($filename, $query_contents);//some file size could be 2mb
file_get_contents($filename);
}
}