Apache 正在记录对“rm”的失败调用;使用 PHP 的 exec()
为了在编辑页面时清除页面的缓存版本,我们用 PHP 编写的 CMS 使用 exec() 来删除所有相关的缓存文件。这些文件的命名始终包含字符串“_lid45”,例如,其中“45”是该页面的唯一标识符。
exec 字符串看起来像这样
rm ../cache/*_lid45[._]*
,只要存在这样的文件,它就可以完美地工作。如果没有,那么用户不会出现任何问题,但 Apache 错误日志会显示一行,就像
rm: cannot remove `../cache/*_lid45[._]*': No such file or directory
我知道这不是最糟糕的事情一样!但如果可以的话,我想尝试删除这些消息,而不向原始脚本添加任何更多负载。例如,我考虑首先使用“ls”来查看是否存在任何此类文件,然后仅在存在时删除它们,但由于缓存的大小有时可能相当大,因此“ls”有时会减慢速度它对整个服务器的性能有显着影响!
有什么想法吗?
In order to clear cached versions of a page when they are edited, our CMS, written in PHP, uses exec() to get rid of all the relevant cache files. These files are always named so as to include the string '_lid45', say, where '45' is the unique identifier for that page.
The exec string will look something like
rm ../cache/*_lid45[._]*
and it works perfectly as long as there exist such files. If there aren't, then nothing goes wrong for the user, but the Apache error log gets a line like
rm: cannot remove `../cache/*_lid45[._]*': No such file or directory
I know this isn't the worst thing to happen! But I would like to try getting rid of the messages, without adding any more load to the original script, if I can. For instance, I thought about using 'ls' first to see if there were any such files, then only deleting them if they were present, but since the size of the cache can sometimes be considerable, 'ls' can occasionally slow down to the point where it has a noticeable effect on the performance of the whole server!
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将
rm
的输出发送到/dev/null
:它就会抑制所有输出,从而抑制错误。
如果您对输出重定向了解不多,您可能会发现这个值得一读...
Just send the output of
rm
to/dev/null
:And it will suppress all the output, which should suppress the errors.
If you don't know much/anything about output redirection, you might find this to be worth a read...