Giter Club home page Giter Club logo

server's Introduction

DriftPHP.

Welcome to DriftPHP, a PHP framework built on top of ReactPHP and Symfony components. Here you have a curated list of components, resources and interesting DriftPHP realted items, specifically designed for you to start using the framework the best and most optimal and efficient way.

Core Components

Adapters

Resources

Others

About us

DriftPHP is packed and maintained by @mmoreram and supported by the community. Don't hesitate to donate if you want this project to be funded.

server's People

Contributors

basster avatar mmoreram avatar nivpenso avatar petronetto avatar seregazhuk avatar tomjvdberg 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

Watchers

 avatar  avatar  avatar  avatar  avatar

server's Issues

Tip for excessive memory usage

Driftphp app run by supervisord (restarts on exit),

this patch:

--- a/vendor/drift/server/src/Application.php
+++ b/vendor/drift/server/src/Application.php
@@ -49,6 +49,9 @@
  */
 class Application
 {
+    private const MAX_MEMORY_MB = 160;
+    private const GLOBAL_CONNECTION_COUNT = 'drift_connection_count';
+
     private LoopInterface $loop;
     private ServerContext $serverContext;
     private string $rootPath;
@@ -111,6 +114,26 @@
             $this->loop
         );

+        $GLOBALS[self::GLOBAL_CONNECTION_COUNT] = 0;
+
+        $socket->on('connection', function($conn) use ($kernelAdapter) {
+            $GLOBALS[self::GLOBAL_CONNECTION_COUNT]++;
+
+            $conn->on('close', function() use ($kernelAdapter) {
+                $GLOBALS[self::GLOBAL_CONNECTION_COUNT]--;
+
+                $memoryUsage = (int) (memory_get_usage() / 1000000);
+                if (
+                    0 === $GLOBALS[self::GLOBAL_CONNECTION_COUNT]
+                    && $memoryUsage > self::MAX_MEMORY_MB
+                ) {
+                    echo "Stopping due to excessive memory usage: $memoryUsage MB" . PHP_EOL;
+                    await($kernelAdapter->shutdown(), $this->loop);
+                    $this->loop->stop();
+                }
+            });
+        });
+
         $http = new HttpServer(
             $this->loop,
             new StreamingRequestMiddleware(),

plus socat relay on the front:

socat TCP4-LISTEN:"$WEB_PORT",reuseaddr,fork,bind="$POD_IP" TCP4:127.0.0.1:"$WEB_PORT",forever,interval=3

($POD_IP because I'm using Kubernetes)

This seamlesly restarts main service, while it is processing requests :)

Check possible multi-CPU usage

This issue is to discuss how we could work with all CPUs at the same time by using a single DriftPHP server. Something like --workers=4.

When running the server with watch argument breakpoints doesn't work using xdebug

This is an issue I found while setting up a development environment.

I haven't explored the issue furthermore, and for that reason, I find it important to add this issue here for further investigation.

When setting debug configuration settings (I use PHPStorm) to run a server with a watch argument, the server doesn't pause on breakpoints except at the bootstrap.php file.

Important note: the same configuration with a run argument works and the program pause at breakpoints.

image

RFC - Fallback for synchronous applications

To continue discussion of #58

I am happy that feature #85 was merged. I am asking myself if we could make the integration of Drift into existing Symfony applications even more simple.

I am asking myself if the changes to the Kernel could be put into a Trait and we could create an AsyncKernelInterface that drift can check against do see if the Kernel supports Async operations.

We would need to make it possible to allow the application to implement async operations on the one hand, which are only enabled if they are running in a Drift context, and fallback to synchronous if they are executed using PHP-FPM.

Using this approach we may could also achieve that existing applications like Sulu, eZ Publish or OroCRM adopt "Drift" as an additional experimental application mode which would extend the popularity and adoption of the project.

The watcher doesn't rebuild the cache when necessary

Currently, the watcher rebuilds the whole container (with cache) only in --debug mode. Which is not used by default (for example, in skeleton).

And it leads to weird errors. For example, I have a controller. And I add a dependency to it. The watcher says that it detects the change and reloads the app. But, the container stays the same. The way the controller is built in the container is outdated. And I receive an error like this:

Too few arguments to function App\Controller\DefaultController::__construct()

I'm not sure that we need to use debug mode always for development. Because recreating a cache for any change looks like a bit overhead ๐Ÿ™ˆ
@mmoreram do you have any ideas how to solve it? Or maybe I'm misusing the server and doing something wrong?

Add SSL support

We should add SSL Support in the server (with SSL feature in socket reactphp package). We could work with these flags

  • --ssl-enabled
  • --ssl-local-cert
  • --ssl-passphrase
  • --ssl-crypto-method

We should add as well a force-ssl flag with a redirection when is needed

  • --force-ssl

streamed request / response not handled correctly

In src/RequestHandler.php#L195 streams are not handled correctly for the request body. Also in the response conversion, the streams get lost.

In symfony/psr-http-message-bridge, there is correct handling for streams.

Set basic request server headers

There are no $_SERVER parameters available in the Symfony request. For the isFromTrustedProxy there is at least the REMOTE_ADDR header required.

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.