Reputation: 10679
I'm currently developing a Web application with Zend Framework
and PHP 5.3
. I have a XML
file that contain configs and mapping information (+- 1500 lines). On each request I perform an xpath
query to get information from that XML
file. The information that is found in the XML
file is static and do not change after the deployment of the application.
It is a good practice to generated a php file that contain the XML
information in a static arrays on the first request and then load that php file on every request to get the information instead of doing queries on the XML
?
Upvotes: 0
Views: 346
Reputation: 337
You can cache the parsed config file as source file with var_export.
Generating code to cache resources is implemented in several places in Zend Framework, for example autoloader, so I presume it is good practice.
There is also another way to cache it - with serialize (make sure to serialize an array, not for example a SimpleXML object) or Zend_Cache which does more or less the same but is more flexible as to how the result is stored.
Upvotes: 1
Reputation: 2243
Since the XML not changes after deploy, i think it would be the best to transform that XML in your local dev env, and not on the productive system when needed. Its not a good idea to generate source on the productive system that will be automatically included without any validation.
I'm not very familiar with XSLT, but it might be an option for you, according to the concrete structure of that XML.
Upvotes: 1