Req #74178 [NEW]: Suggestion/Idea: Stateful / Application Script
| From: | alex at alex-at dot ru | Date: | Mon, 27 Feb 2017 18:34:47 +0000 |
| Subject: | Req #74178 [NEW]: Suggestion/Idea: Stateful / Application Script | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-207585@lists.php.net to get a copy of this message | ||
From: alex at alex-at dot ru
Operating system:
PHP version: Next Major Version
Package: FPM related
Bug Type: Feature/Change Request
Bug description:Suggestion/Idea: Stateful / Application Script
Description:
------------
Many current PHP scripts suffer from necessity of (re)initializing lots
of state from startup to real serving. Even using
Opcache/Memcached/whatever, initialization of all database/cache/etc.
connections and classes takes ages.
So why just not bring common 'appserver' paradigm to PHP?
Basically, it all boils to implementation of a single function:
run_as_stateful($callback, $timeout = null) or something like that.
What should it do: it should clean up all volatile request and session
variables, and make server know script is ready to accept new request to
it. Everything else related to process should remain intact: variables,
classes, objects, database/cache connections, open files, other
resources, whatever.
When a new request to the same script comes, and there is some stateful
script process idling, request gets scheduled to one of these processes.
Request variables get filled (session ones do not, until new
session_start call in PHP code), and $callback gets executed. Basically,
that's all. This will allow $callback to skip all the unnecessary
initialization, getting through only to request-based serving.
Once $callback executes, it can either "exit", causing script process to
terminate, or just "return", causing script to wait for a new request,
or call run_as_stateful() anew, refreshing $timeout. Any error of course
causes script process to terminate.
$timeout here is a timeout for script process to be waiting for requests
(idling) in total (each period counts, or may be refreshed within
$callback), after which process terminates.
If there are no running stateful script processes at the moment of
request, request is scheduled to normal PHP execution strategy, without
any changes required.
File change detection can be optionally either ignored or delegated to
opcache with its change detection strategy, and terminate all idling
stateful script processes / set terminate flag to all running stateful
script processes so they terminate at next idle loop.
The idea/suggestion is mainly intended for FPM I think, because it has
process control and can be extended with any tunables needed, like
maximum lifetime of a stateful script, maximum count of stateful scripts
running (total and per script), list of scripts that are allowed to run
as stateful, etc.
--
Edit bug report at https://bugs.php.net/bug.php?id=74178&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74178&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74178&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74178&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74178&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74178&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74178&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74178&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74178&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74178&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74178&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74178&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74178&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74178&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74178&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74178&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74178&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74178&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74178&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74178&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74178&r=mysqlcfg