PHP and sharing resources between requests

爷,独闯天下 提交于 2021-01-27 06:31:40

问题


I'm looking for a way to share PHP resources between requests. First of all, I want to share parsed XML. I have some large XML that I use in readonly mode, and currently I have to load and parse it for each HTTP request.

I've read this: http://php.net/manual/en/function.shm-put-var.php and the other shared memory API documentation, and I know that there is no straight way to store resources in shared memory. That's why I ask here.

So, I have XML, I use it in readonly mode (performing XPath-requests), this XML is large, and I'm looking for some way to eliminate the need of loading and parsing it for each HTTP request. Any ideas or advices about this?

Thank you.


回答1:


If you have APC enabled on your server, take a look at apc_store

http://php.net/manual/de/function.apc-store.php

Unlike many other mechanisms in PHP, variables stored using apc_store() will persist between requests (until the value is removed from the cache)




回答2:


You can use sessions for this http://www.tizag.com/phpT/phpsessions.php that's what they are build for.

As a website becomes more sophisticated, so must the code that backs it. When you get to a stage where your website need to pass along user data from one page to another, it might be time to start thinking about using PHP sessions.




回答3:


Perhaps you can use memcache and save the object or the file in memcache. Then any Webservice can load the file and work with it. Memcache is very fast and you can access it from many Webservers.



来源:https://stackoverflow.com/questions/11283568/php-and-sharing-resources-between-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!