PHP等同于ASP.NET应用程序/缓存对象 [英] PHP equivalent of ASP.NET Application/Cache objects

查看:45
本文介绍了PHP等同于ASP.NET应用程序/缓存对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Google-fu没有透露我在寻找什么,所以我将它发布给了人群。

My Google-fu hasn't revealed what I'm looking for, so I'm putting this one out to the crowd.

来自ASP。 NET开发背景,我习惯于使用 Application Cache 集合来存放很少修改的内容,但经常使用的资源(例如来自数据库的查找行或静态XML文档的内容)位于Web服务器的内存中,因此我不必在每次请求时都重新加载这些经常使用的项目。

Coming from an ASP.NET development background, I'm used to having the Application and Cache collections available for me to stash rarely-modified but often-used resources (such as lookup rows from a database or the contents of static XML documents) in the memory of the web server, so I don't have to reload these often-used items during every request.

PHP是否具有等效功能?我已经简单阅读了Memcache扩展程序,但是这对我来说不起作用(因为我无法控制服务器配置。)我很想实现允许我进行预先准备或预先准备的内容选择资源并生成一种PHP缓存文件,该文件将从存储在文件中的文字构造出缓存的对象,但这对我来说似乎是一个非常棘手的解决方案。

Does PHP have an equivalent? I've read up briefly on the memcache extension, but this won't work for me (as I don't have control over the server configuration.) I'm tempted to implement something that would allow me to pre-parse or pre-select the resources and generate a sort of PHP cache "file" that would construct the cached object from literals stored in the file, but this seems like a very hacky solution to me.

PHP中是否有某些东西(或者某种形式的帮助程序库)可以让我使用最佳实践来完成此工作?

Is there something in PHP (or, alternatively, a helper library of some sort) that will allow me to accomplish this using best practices?

推荐答案

简而言之,不,PHP本身不提供这种功能。要了解原因,您必须了解PHP具有针对每个请求构建的整个环境,并且随后在请求结束时将其拆除。 PHP 确实为您提供$ _SESSION来存储每个会话变量,但是在深入研究文档之后,您会看到该变量也在每次请求期间生成。 PHP(或更具体而言,mod php)与其他应用程序服务器根本不同。基本上,它不是应用程序服务器。它是每个请求脚本运行程序。

In short, no, such a thing is not available natively in PHP. To understand why, you have to understand that PHP has its entire environment built for each request, and it is subsequently torn down at the end of the request. PHP does give you $_SESSION to store per session variables, but after digging into the docs you will see that that variable is built during each request also. PHP (or mod php to be more specific) is fundamentally different from other "application servers". Basically, it is not an application server. It is a per request script runner.

现在,不要误会我的意思,PHP允许您进行应用程序级别的数据存储,但是您必须使用数据库或磁盘来获取它。不过请记住这一点,在显示性能问题之前,不必担心性能优化。而且我会猜到,有100台设备中有99台是性能问题,这并不是由于您编写的代码不佳而引起的,您将有资源来构建自己的小型内存缓存服务器。

Now, don't get me wrong, PHP lets you do application level data store, but you will have to go to a database, or to disk to get it. Remember this though, don't worry about optimizing for performance until it is shown that preformance is a problem. And I will guess that 99 times out of 100, by the time performance is an issue that isn't due to some poor code you wrote, you will have the resources to build your own pretty little memcached server.

这篇关于PHP等同于ASP.NET应用程序/缓存对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆