I am writing some files in the filesystem, but unfortunately these files are deleted at the exit of the PHP script.
I have tried to create the files both with fopen (w+) and file_put_contents. Files are regularly deleted.
Any ideas?
EDIT: Files are written to /home/ontw/webshop/definitions1/, which is not a temporary directory.
some code:
$fp = fopen($filename, "w+");
if ($fp == false) {
throw new RuntimeException("Could not create $filename (fopen error)!");
}
if (flock($fp, LOCK_EX)) {
if (false === fwrite($fp, $contents)) {
throw new RuntimeException("Could not create $filename (fwrite error)!");
}
fflush($fp);
flock($fp, LOCK_UN);
} else {
throw new RuntimeException("Could not create $filename (unable to get file lock)!");
}
fclose($fp);
I found the bug. The deletion was performed inside a __destruct
statement. It seems that all the destructors are called on exit()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.