phpfastcgi / fastcgidaemon Goto Github PK
View Code? Open in Web Editor NEWA FastCGI daemon written in PHP.
Home Page: http://phpfastcgi.github.io/
License: MIT License
A FastCGI daemon written in PHP.
Home Page: http://phpfastcgi.github.io/
License: MIT License
Move the console command from the SpeedfonyBundle into the daemon so that it can be used for other framework implementations.
When a large POST request comes in, my script dies. Input is read over STDIN. Smaller request have no issue.
PHP Notice: Undefined offset: 0 in /home/alex/projects/fcgi/vendor/phpfastcgi/fastcgi-daemon/src/Driver/Userland/Connection/StreamSocketConnectionPool.php on line 70 PHP Fatal error: Uncaught TypeError: Argument 2 passed to PHPFastCGI\FastCGIDaemon\Driver\Userland\ConnectionHandler\ConnectionHandlerFactory::createConnectionHandler() must implement interface PHPFastCGI\FastCGIDaemon\Driver\Userland\Connection\ConnectionInterface, null given, called in /home/alex/projects/fcgi/vendor/phpfastcgi/fastcgi-daemon/src/Driver/Userland/UserlandDaemon.php on line 102 and defined in /home/alex/projects/fcgi/vendor/phpfastcgi/fastcgi-daemon/src/Driver/Userland/ConnectionHandler/ConnectionHandlerFactory.php:16 Stack trace: #0 /home/alex/projects/fcgi/vendor/phpfastcgi/fastcgi-daemon/src/Driver/Userland/UserlandDaemon.php(102): PHPFastCGI\FastCGIDaemon\Driver\Userland\ConnectionHandler\ConnectionHandlerFactory->createConnectionHandler(Object(PHPFastCGI\FastCGIDaemon\CallbackWrapper), NULL) #1 /home/alex/projects/fcgi/vendor/phpfastcgi/fastcgi-daemon/src/Driver/Userland/UserlandDaemon.php(74): PHPFastCGI\FastCGIDaemon\Driver\Use in /home/alex/projects/fcgi/vendor/phpfastcgi/fastcgi-daemon/src/Driver/Userland/ConnectionHandler/ConnectionHandlerFactory.php on line 16 </code>
hi,is it support php7.1 7.2...
Hi!
I'm just taking a look this project, and I think it's extremely interesting. I always thought it was a possibility to do something like this, and now finally somebody has done it. Could be a revolution =)
My main request: the following dependencies could be considered optional:
These dependencies create bit of a dependency graph, but really you only need one of those depending on which http request/response library you'd want to use. Would it be a possibility to make those deps require-dev
and suggests
, so if somebody uses PSR-7, they don't also need to include symfony/http-foundation
?
if i update the business code, how can i make it effective. for example.in php fpm i can fpm reload
Integrate PSR logging interfaces
I've successfully gotten a fairly large Symfony 2 application working under FastCGIDaemon. Initial testing shows up to 400ms saved per request!
However, I ran into some issues with handling multiple simultaneous sessions. I gutted the Symfony 2 handling (other than HttpFoundation Request/Response) to try to get an understanding of how PHP is handling things. Here's what I've got so far:
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use PHPFastCGI\FastCGIDaemon\ApplicationFactory;
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
$stream = fopen('php://stdout', 'w');
ini_set('session.use_cookie', false);
$kernel = function (RequestInterface $originalRequest) use ($stream) {
$request = $originalRequest->getHttpFoundationRequest();
fwrite($stream, $request->headers."\n");
if ($sessId = $request->cookies->get(session_name())) {
session_id($sessId);
} else {
session_id(hash('sha1', uniqid(mt_rand(), true)));
}
session_start();
if (!isset($_SESSION['test'])) {
fwrite($stream, 'Saving test!'."\n");
$_SESSION['test'] = 'thing';
} else {
fwrite($stream, 'Showing test: '.$_SESSION['test']."\n");
}
$response = Response::create();
$cookieParams = session_get_cookie_params();
$response->headers->setCookie(new Cookie(session_name(), session_id(), time()+86400, $cookieParams['path'], $cookieParams['domain'], $cookieParams['secure'], $cookieParams['httponly']));
fwrite($stream, $response->headers."\n");
session_write_close();
return $response;
};
$application = (new ApplicationFactory)->createApplication($kernel);
$application->run();
This works, though obviously ugly. Key points:
session_get_cookie_params()
so that the ini settings could be used.Thoughts:
SessionHandlerInterface
will invariably be a better solution. This also gives you a clear place to implement the regenerating of a session_id (by setting a create_sid
callback [yes, that means the old session_set_save_handler
prototype must be used]).session.use_cookie
might not be necessaryI'm concerned that I'm missing something as far as maintaining session security (preventing hijacking or fixation). Since this code blindly checks for a PHPSESSID
cookie, it would be a trivial affair to hijack someone else's session, if you could guess the ID. However, I don't think this logic differs from the built-in default PHP session_id validation logic, so maybe it's a moot point.
Im currently using phalcon framework, how to implement adapter for your phpfastcgi ? Any hints ? Creating something similar like for slim/symfony/silex is enough ?
Allow daemon to be shutdown when a memory or request limit is reached.
Shutdown modes should allow for:
I've described my situation here: yiisoft/yii2#14646
I did a quick and dirty integration between FastCGIDaemon and my Yii2 app.
With php-fpm I got ~5k rps. With FastCGIDaemon I reached ~8k rps.
I have nginx + 32 FastCGIDaemon workers, managed by supervisord.
Under the load of 8k rps, all 16 CPU cores are fully loaded.
That's a big improvement, sure, but I've expected much higher performance increase since now I get rid of bootstrapping framework on every request. My similar node.js application is still many times faster on same machine.
I wonder if this is expected level of performance increase?
What else can I try?
But wait for some PRs to be merged to avoid conflicts.
Hello, just noticed your daemon and liked it, because it has many common with things that I do (private repo for now). I have an OOP library for working with FCGI: https://github.com/lisachenko/protocol-fcgi and think that it can be used for you needs as a low-level transport implementation.
What do you think about this?
Thanks!
This is helpful for debugging
Add support for uploaded files
Currently, there are a few more public methods in the Request class than the interface. We should either remove those functions or update the interface.
https://github.com/PHPFastCGI/FastCGIDaemon/blob/master/src/Http/Request.php
Create a class "PHPFastCGI\FastCGIDaemon\CommandFactory"
Should have the methods:
For creating symfony commands and applications using the default implementations provided by the library.
Put +1 to support my message
░░░░░░░░░░░░▄▄
░░░░░░░░░░░█░░█
░░░░░░░░░░░█░░█
░░░░░░░░░░█░░░█
░░░░░░░░░█░░░░█
███████▄▄█░░░░░██████▄
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█████░░░░░░░░░█
██████▀░░░░▀▀██████▀
Create a class for instantiating daemon objects to make implementations more testable.
Hi there!
I just did my first FastCGI implementation. It was fairly simple to get it up and running. The big thing I'm thinking about now though is, how is this actually going to improve performance? Given that currently the request-response sequence happens in one synchronous process, this effectively will mean that if a user triggers a request that takes more than a second (due to a slow mysql query), every other user will have to wait till that request has finished.
Is there an internal API that will allow me to get the daemon to parse incoming requests, and send responses back asynchronously? If so, I'll be able to integrate an event loop...
See #39 for example
After profiling the software I realised that the creation of PSR-7 messages was a bottle neck in the application under full load.
I suspected that Symfony HttpFoundation messages were quicker to create, as benchmarks from before PSR-7 support in the project were faster than the ones recently published.
Seeing as Symfony and Silex adapters are both flagship adapters for this project, it makes no sense to instantiate PSR-7 messages inside the core of the FastCGIDaemon - only for them to later be converted to HttpFoundation messages.
A simple FastCGI request object (that can be rapidly instantiated) replaces the PSR-7 server request object inside the FastCGIDaemon core.. The object also contains some simple methods for basic information about the request (so it could be used as a request object in its own right). The two most important methods are factory methods for PSR-7 server request objects and HttpFoundation request objects which allow implementations to choose which type of request object to work with at their own cost.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.