Giter Site home page Giter Site logo

fastcgidaemon's People

Contributors

andrewcarteruk avatar carlos-ea avatar gaaf avatar hason avatar kamilbalwierz avatar khanhicetea avatar nyholm avatar tyler-sommer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastcgidaemon's Issues

Fails with large POST requests

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>

Possibility to make some dependencies optional?

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:

  • psr/http-message
  • zendframework/zend-diactoros
  • symfony/http-foundation

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 ?

Handling sessions

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:

  • You must generate your own session ID, always. PHP seems to want to keep the last used ID if it is not explicitly overwritten.
  • You must set the cookie on the response manually. I used session_get_cookie_params() so that the ini settings could be used.

Thoughts:

  • Implementing a 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]).
  • Disabling session.use_cookie might not be necessary

I'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.

Phalcon Adapter

Im currently using phalcon framework, how to implement adapter for your phpfastcgi ? Any hints ? Creating something similar like for slim/symfony/silex is enough ?

Shutdown options

Allow daemon to be shutdown when a memory or request limit is reached.

Shutdown modes should allow for:

  • immediate shutdown
  • graceful shutdown (stops accepting new requests)
  • shutdown when no requests in system

Yii2: expected more significant performance improvement.

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?

Create command factory

Create a class "PHPFastCGI\FastCGIDaemon\CommandFactory"

Should have the methods:

  • createCommand($kernel)
  • createApplication($kernel)

For creating symfony commands and applications using the default implementations provided by the library.

Thank you for all you done

Put +1 to support my message

░░░░░░░░░░░░▄▄
░░░░░░░░░░░█░░█
░░░░░░░░░░░█░░█
░░░░░░░░░░█░░░█
░░░░░░░░░█░░░░█
███████▄▄█░░░░░██████▄
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█░░░░░░░░░░░░░░█
▓▓▓▓▓▓█████░░░░░░░░░█
██████▀░░░░▀▀██████▀

DaemonFactory

Create a class for instantiating daemon objects to make implementations more testable.

Concurrency

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...

HTTP Request Messages

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.