Pergunta

I've done a fair bit of PHP over the years but I'm currently learning ColdFusion and have come across the Application.cfc file.

Basically this is a class that's created once (has an expire date). The class handles incoming users and can set session variables and static memory objects, such as queries. For example I can load site wide statistical data for one user in another thread from the Application.cfc. Something that would usually take a few seconds for each page would make the whole site quick and responsive.

Another example (just for clarification). If I put an incremental variable that's set to 0 in OnApplicationStart this variable can be incremented with each user request (multiple users) or in OnSessionStart without the need to contact the SQL database since it's constantly in the server's memory under this application.

I was wondering if PHP has a similar file or object? Something that can be created once and used to store temporary variables?

Foi útil?

Solução

The PHP runtime itself initializes the environment from scratch on every HTTP request, so it has no built-in mechanism to do this. Of course you can serialize anything into common storage and then read it back and deserialize on each request, but this is not the same as keeping it in-memory.

This type of functionality in PHP is achieved by outsourcing to other programs; memcached and APC are two of the most commonly used programs that offer such services, and both come with PHP extensions that simplify working with them.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top