Req #66100 [Opn->Wfx]: Add a persistent "application" like mode to PHP

From: Date: Tue, 19 Nov 2013 07:43:44 +0000
Subject: Req #66100 [Opn->Wfx]: Add a persistent "application" like mode to PHP
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182818@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66100&edit=1

 ID:                 66100
 Updated by:         rasmus@php.net
 Reported by:        thecmann1 at gmail dot com
 Summary:            Add a persistent "application" like mode to PHP
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            *General Issues
 PHP Version:        5.4.22
 Block user comment: N
 Private report:     N

 New Comment:

No, this is not going to happen. This quickly becomes a scalability nightmare. PHP's perfect
sandbox is exactly what gives it unlimited horizontal scalability.

Some of your issues are addressed in a generic scalable way through opcode caches and persistent
database connections.

Anything else belongs in an Application Server which is outside the scope of the PHP project.


Previous Comments:
------------------------------------------------------------------------
[2013-11-15 09:26:42] thecmann1 at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=66100&edit=1


Thread (6 messages)

« previous php.bugs (#182818) next »