|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-11-19 07:43 UTC] rasmus@php.net
-Status: Open
+Status: Wont fix
[2013-11-19 07:43 UTC] rasmus@php.net
[2013-11-19 08:03 UTC] thecmann1 at gmail dot com
[2013-11-19 08:12 UTC] rasmus@php.net
[2014-04-06 15:46 UTC] james at billingham dot net
[2014-04-08 10:15 UTC] rasmus@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 10:00:01 2025 UTC |
Description: ------------ Currently any PHP script is run from scratch every time a request is made to a PHP page; there is nothing wrong with this if you are doing something simple, or you have limited resources or you are using a shared hosting package. But you can also use PHP to develop an entire application where all requests to the site are usually run through the application's entry point. In this case each time a page is viewed the script has to start all over again, possibly connecting to the database, reading configuration files, etc. which all seems like a huge waste of time to me especially if this is the only program running on the server. What I suggest is a way to request that a single PHP file/process be kept in memory between page requests. What you will do is register a certain class as an application, which will link the current file path with the current PHP process. Then the class that you provide will contain special functions which will be called to handle page request. See below for an idea of what I have in mind. I'm not sure on exactly when a script will be shut down but perhaps if no requests have been made to it after a certain period or if it is not currently running and the memory is needed by other processes. Test script: --------------- <?php class Main{ // This function is called the very first time that the script is run. // Here you can load configuration files and load commonly used data from the database to be kept in memory public function onStart(){} // This function will be called when the script is shut down for whatever reason. // Here you can save any modified configuration files or data. public function onStop(){} // This function will be called eveery time a page request is sent to this script. // Possibly some kind of request object can be passed to this function caontaining // all the usual request variables: url, cookies, referer, etc. public function onRequest(){} } // A special function will be used to register a class as an application. // Now any requests made to this file will instead be passed to the Main->onRequest // function that is in memory instead of re-running this file. register_application(Main);