Req #66100 [NEW]: Add a persistent "application" like mode to PHP
| From: | thecmann1 at gmail dot com | Date: | Fri, 15 Nov 2013 09:26:43 +0000 |
| Subject: | Req #66100 [NEW]: Add a persistent "application" like mode to PHP | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-182771@lists.php.net to get a copy of this message | ||
From: thecmann1 at gmail dot com
Operating system:
PHP version: 5.4.22
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:Add a persistent "application" like mode to PHP
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);
--
Edit bug report at https://bugs.php.net/bug.php?id=66100&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66100&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66100&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66100&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66100&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66100&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66100&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66100&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66100&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66100&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66100&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66100&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66100&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66100&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66100&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66100&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66100&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66100&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66100&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66100&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66100&r=mysqlcfg