[英]files created by PHP deleted on exit
I am writing some files in the filesystem, but unfortunately these files are deleted at the exit of the PHP script. 我正在文件系统中写一些文件,但是不幸的是这些文件在PHP脚本的出口处被删除了。
I have tried to create the files both with fopen (w+) and file_put_contents. 我试图用fopen(w +)和file_put_contents创建文件。 Files are regularly deleted. 文件会定期删除。
Any ideas? 有任何想法吗?
EDIT: Files are written to /home/ontw/webshop/definitions1/, which is not a temporary directory. 编辑:文件被写入/ home / ontw / webshop / definitions1 /,这不是一个临时目录。
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. 删除是在__destruct
语句中执行的。 It seems that all the destructors are called on exit()
似乎所有析构函数都在exit()
上调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.