Windows/Wamp環境にキャッシュスクリプトを持つアプリケーションを作成しました。このスクリプトのキャッシング機能は同時に1回だけ実行できます。ubuntuでPHPの 'x +'が動作しない
これを達成するために、「ロックファイル」を使用して、それが存在するかどうかを確認しました。
Windowsでは、このスクリプトは正常に動作し続けます。しかし、今はUbuntu環境に移行しても動作しません。
<?php
date_default_timezone_set('Europe/Amsterdam');
ini_set('max_execution_time', 300);
ignore_user_abort(true);
$path = 'locked.txt';
if ($lock = fopen($path,'x+')) {
fwrite($lock,time());
fclose($lock);
sleep(10);
unlink($path);
}
?>
エラー:あなたが "X +" を使用してロックファイルとしてファイルを使用しようとしているあなたの説明から、
x+ Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
:PHPのドキュメント(ビットを言い換え)からfopen(locked.txt): failed to open stream: Permission denied
'@fopen'は、問題が何であるかを示す可能性のあるエラーを抑制しています。 – apokryfos
@apokryfosは抑止 '@'を削除しました。しかし、エラーはありません。私はまた、簡単なコードで自分の投稿を編集しました。 – kgongonowdoe
コードをコピーして貼り付けました。私の14.04 ubuntuでうまく動作します。ディレクトリに対して実行権限があることを確認してください。そうしなければ削除できません。 – apokryfos