使用 PHP 输出缓冲时我需要关心竞争条件吗?
我想缓存单个 php 文件的结果(几分钟)。阅读了几篇文章后,这似乎很简单,例如遵循 http://www .addedbytes.com/articles/caching-output-in-php/
但是,在 http://simas.posterous.com/php-data-caching-techniques,作者说应该对文件进行锁定,但我在网上的任何示例中都看不到锁定。这是必需的吗?我该怎么做呢?
多谢!
I would like to cache the result of a single php file (for a few minutes). Having read a few articles, this seems pretty easy, e.g. following http://www.addedbytes.com/articles/caching-output-in-php/
However, at the end of http://simas.posterous.com/php-data-caching-techniques, the author says that file locking should be done and I cannot see locking in any examples online. Is this required? How should I do it?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,我们使用 Nette 的 NSafeStream 类 - 它提供线程安全文件访问:
NSafeStream
您不需要使用框架的其余部分,您可以只使用此类。
We use Nette's NSafeStream class for this - it provides thread safe file access:
NSafeStream
You don't need to use rest of the framework, you can use just this class.
看看这个: http://php.net/manual/en/function.flock .php
Take a look at this : http://php.net/manual/en/function.flock.php