tags:

views:

30

answers:

2

In PHP there are many Frameworks and all of them have the Concept of Front Controller or Entry Script or Application. Basically all of them mean that on a Http Request by a Browser , an Application Instance is created ( Like in Zend Framework , Instance of Zend_Application and Yii::createWebApplication in Yii) and each Application Instance further initializes different Components ( Nested Property Objects ) like Controller Object , DB Object , View Object (mostly Child Property Object of Controller Object) , Request and Response Objects etc.

I hope it is clear till now . It must be the same in every MVC Framework :) No matter what Language

What I was curious to know about that Is this Application Instance created ( along-with its nested child objects ) every Time a User Clicks on a Browser Button or Link and makes a HTTP Request or AJAX Request ?

I think in Java Application Instance is persistent throughout Requests , maybe I am wrong :)

Is it persistent in PHP , What are the Limitations if not ?

Thanks for your Attention

A: 

In a stock PHP, everything's rebuilt and/or reloaded on each request. There may be modified versions of PHP (or third-party extensions that talk to a state server service or something) that can keep app-wide state in memory, but you'd have to look for them.

The main drawback of this, besides the overhead of restoring everything to a runnable state, is that the site normally can't do anything if it's not processing a request. There are workarounds, like cron jobs / scheduled tasks, but they wouldn't be necessary if the app were "running" the whole time.

cHao
That must be really hard on a Server processing PHP :)
Rohit Chauhan
PHP isn't as slow as you'd think. :) If there's not an inordinate amount of stuff to load, and particularly if you're using something like mod_php that keeps a PHP interpreter loaded and ready to run, it's decently fast for all but the busiest sites.
cHao
A: 

Unfornunatly the only way to remotely have some kind of statefull processing in PHP is by use of Sessions (and indirectly cookies). And even if you use the session to save your state it will have to be rebuild on the next request.

jpluijmers
Via serialization, a framework could (and in a few cases, *does*) easily support app-wide state that is loaded and saved, much like session state, on each request. But the key, and the answer to the question being asked -- is that last part: "is loaded and saved...on each request".
cHao