Re: [FPM] Reused PHP script as daemon process

From: Date: Wed, 23 Apr 2014 22:30:00 +0000
Subject: Re: [FPM] Reused PHP script as daemon process
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-73768@lists.php.net to get a copy of this message
I simplified the example, it is possible to discuss in detail the API There are two options, a high-level API abstraction from SAPI or low tier API which depends on the SAPI Abstract API spl_server_loop(callable $name) The infinite receiving new requests and run custom callable. PHP send response to the client automatically, all the user response headers and body (ob_get_contents()). After each iteration makes ob_clean(). Sample: <?php $callable = function() { MyFrameWork::run(); } // This code execute once MyFrameWork::init($config); //... // This infinite receiving new requests and run custom callable spl_server_loop($callable); ?> Historically that PHP developers are abstracted from SAPI. Continue the practice for daemon process script. Or use SAPI fastcgi_handle_request(callable $name) fastcgi_parse_request($input_stream_or_string); fastcgi_encode_response($code, $headers, $body); But then your code will run on only one SAPI, such work as Apache module, this code can not. The meaning of this API to allow the user complete control processes without the possibility of transfer to other SAPI 2014-04-22 14:12 GMT+03:00 Alexey Zakhlestin <indeyets@gmail.com>: > > On 22 Apr 2014, at 02:27, Park Framework <park.framework@gmail.com> wrote: > > > Add, function fastcgi_handle_request(callable $name) for reused script as > > daemon process. > > > > With each new request, all superglobals variables ($_GET, $POST, > $_COOKIE, > > $_SERVER, ...) with new values from current ​​request. > > Exposing FastCGI lib to userland is something we already were talking > about, but I don’t think your choice of API is good. > > Something like this would be much cleaner: > > $data = fastcgi_parse_request($input_stream_or_string); > > Then, you can call your handler manually, and: > > echo fastcgi_encode_response(200, ['hea' => ['de', 'rs']], > $body); > > lower-level functions could be useful too (for partial answers, etc.) > > -- > Alexey Zakhlestin > CTO at Grids.by/you > https://github.com/indeyets > PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc > > > >

« previous php.internals (#73768) next »