PHP file_put_contents() 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4118065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP file_put_contents() error
提问by rightsound
Everytime I try to modify a file, I get this error and I don't know what it means:
每次我尝试修改文件时,都会收到此错误,但我不知道这意味着什么:
A PHP Error was encountered
Severity: Warning
Message: file_put_contents() [function.file-put-contents]: Only 0 of 19463 bytes written, possibly out of free disk space
Filename: Template/String.php
Line Number: 369
I tried looking for solutions and so far none of them made sense, well, in my opinion.
我试图寻找解决方案,但到目前为止,在我看来,它们都没有意义。
Any thoughts? A little help here please. Thank you very much.
有什么想法吗?请在这里提供一些帮助。非常感谢。
回答by Chad Clark
This is an old question but it comes up when Googling for the error message. Here is another possible cause for this error message.
这是一个老问题,但在谷歌搜索错误消息时会出现。这是此错误消息的另一个可能原因。
The ext2/3/4 filesystems can reserve disk space for root. Often it is 5% of the drive. df shows the drive is not entirely used. Root can write to the drive. Non-root users will only be able to create files but not write any data to them. See dumpe2fs and tune2fs for more details.
ext2/3/4 文件系统可以为 root 保留磁盘空间。通常它是驱动器的 5%。df 显示驱动器未完全使用。Root 可以写入驱动器。非 root 用户只能创建文件,但不能向其中写入任何数据。有关更多详细信息,请参阅 dumpe2fs 和 tune2fs。
回答by joshuahedlund
You may need to increase the quota for that user on the server. You can confirm this by deleting a file and seeing if it will let you re-upload that file, but nothing further.
您可能需要增加该用户在服务器上的配额。您可以通过删除文件并查看它是否会让您重新上传该文件来确认这一点,但仅此而已。
If you have Webmin, go to System > Disk Quota. (For a detailed explanation, see this wiki.)
如果您有 Webmin,请转到系统 > 磁盘配额。(有关详细说明,请参阅此 wiki。)
If you do not have Webmin or a similar interface, you will need to look up how to manually edit the user quota settings depending on which Linux distro you are using.
如果您没有 Webmin 或类似的界面,则需要根据您使用的 Linux 发行版查找如何手动编辑用户配额设置。
If you do not have access to the server you will need to contact the person who does and ask what your disk quota is and if it can be increased.
如果您无权访问服务器,则需要联系访问该服务器的人员并询问您的磁盘配额是多少以及是否可以增加。
回答by Tim Post
This probably means that PHP is able to get a valid file descriptor, but is hitting a wall (such as a quota, sticky bit, etc) when actually trying to write the data.
这可能意味着 PHP 能够获得有效的文件描述符,但在实际尝试写入数据时遇到了障碍(例如配额、粘滞位等)。
It is also conceivable that you are writing (perhaps unwittingly) to a network file system that is having a problem with its peer.
也可以想象您正在(可能是在不知情的情况下)写入对等方有问题的网络文件系统。
More information regarding your platform would help (I've seen SELinux do strange things when improperly configured), but I think you get the gist of what to check.
有关您的平台的更多信息会有所帮助(我已经看到 SELinux 在配置不当时会做一些奇怪的事情),但我认为您已经了解了要检查的内容的要点。
回答by SlamDunk
It's just a permission to where you wanted to save the content, e.g. readonly or just like the error itself, no disk space.
这只是您想要保存内容的位置的权限,例如只读或就像错误本身一样,没有磁盘空间。
回答by Anmol Shrivastava
For me I was also having the same set of errors on my login page. While exploring I found that the storage/logs/laravel.log
file has grown up to the size of 24G. And clearing it solved the issue. To find out the size of directory use linux command du -sh *
or du -sh <filename>
. To clear up the log file using truncate command is the best option. Because oping with vim and deleting could be difficult because of Heavy size of the file. For truncating use the command truncate -s 0 <filename>
对我来说,我的登录页面上也出现了同样的错误。在探索的过程中,我发现storage/logs/laravel.log
文件已经增长到 24G 的大小。清除它解决了这个问题。要找出目录的大小,请使用 linux 命令du -sh *
或du -sh <filename>
. 使用 truncate 命令清除日志文件是最好的选择。因为文件很大,所以使用 vim 操作和删除可能很困难。截断使用命令truncate -s 0 <filename>
回答by Pato Mbugua
I went to the root directory
我去了根目录
cd /
and searched for the folder that had the biggest space usage with
并搜索空间使用量最大的文件夹
du -sh *
from there I was able to trace the file giving the headache, pluto.log in /var/log. this could be any file.
从那里我能够追踪到 /var/log 中令人头疼的文件 pluto.log。这可以是任何文件。
回答by Oswaldo Rodriguez Gonzalez
Maybe you have a previous lock on your target file, try to:
也许您之前锁定了目标文件,请尝试:
$fp = fopen('yourfile.etc', 'r+');
if (!flock($fp, LOCK_EX | LOCK_NB)) {
//this file is actually being used from another script / user, that's the problem.
} else {
//ok, there wasn't lock on it, must be something else
fclose($fp);
}