php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66100 Add a persistent "application" like mode to PHP
Submitted: 2013-11-15 09:26 UTC Modified: 2014-04-08 10:15 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: thecmann1 at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.4.22 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-11-15 09:26 UTC] 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);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-19 07:43 UTC] rasmus@php.net
-Status: Open +Status: Wont fix
 [2013-11-19 07:43 UTC] rasmus@php.net
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.
 [2013-11-19 08:03 UTC] thecmann1 at gmail dot com
Thanks for the reply, I'm no expert so I don't have enough experience to know what the advantages and disadvantages of something like this could be.
My idea though is that you wouldn't be forced to run it this way, it could still be used the way it currently is.

Would you mind explaining why it wouldn't be scalable? And also what exactly you mean by 'PHP's perfect sandbox' and 'unlimited horizontal scalability' and why the feature I suggested would'nt allow for this.
 [2013-11-19 08:12 UTC] rasmus@php.net
Because you are talking about keeping things in memory. That implies a single server. That means as soon as you want to scale your application to multiple load balanced servers you have a problem.
 [2014-04-06 15:46 UTC] james at billingham dot net
@rasmus

That is an issue of application design. There are many instances with many web frameworks/tools where objects are kept in memory without any impact on load balancing ability.

The memory should not be used to persist data - that would be stupid as it's volatile anyway. It would be used to avoid having to bootstrap your entire application on every request & to cache.

Presumably it would be possible to yield large performance improvements in complex applications such as MVC by only bootstrapping once.
 [2014-04-08 10:15 UTC] rasmus@php.net
It still isn't going to happen. It violates the basic principle of PHP's perfect shared nothing sandbox.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 13:01:27 2024 UTC