WSGI / Rack for PHP

    Historically, PHP scripts run on every HTTP request. When launched, the script performs some initialization (for example, establishes a connection to the DBMS), after which it analyzes the request and generates a response. However, everyone is well aware that a different approach has been taken in the world of Python and Ruby: web applications in these languages ​​are loaded into memory at the same time as the web server (or application server). The application server interacts with the script using the standard WSGI and Rack interfaces. This approach, of course, is not without drawbacks, the main of which, perhaps, is associated with a sharp increase in overhead when placing a large number of sites on one server, however, has an important advantage: initialization is performed only once, then the script only responds to incoming HTTP inquiries.

    Attempts to transfer the request processing cycle to the body of the PHP script have already been made , while it was possible to achieve a significant increase in productivity. However, for this I had to write quite a lot of code.

    However, just the other day, the creators of uWSGI implemented experimental supportan interface similar to WSGI / Rack for PHP. I remind you that uWSGI is an extremely flexible and functional application server that supports almost all languages ​​and technologies that exist today, which can easily be used as an alternative to PHP-FPM. Thus, it became possible to create web applications that were constantly loaded into memory, with much less blood.

    The interface is called "phpsgi". The plugin that implements support for this interface is still rather dank, however, the developer has already expressed a desire to show it to the general public.

    But i will absolutely ask you for tests / reports and for gathering people willing to try it :)

    Installing the plugin with uWSGI already configured is extremely simple:

    uwsgi --build-plugin

    After executing such a command, the file “” appears in the current directory, which is sufficient to place in the directory with the other server plug-ins (usually / usr / lib / uwsgi). After that, you can configure the vassal (virtual node), or run the uWSGI instance manually. For simplicity, consider the second option.

    uwsgi --plugin phpsgi --http-socket :9090

    If you execute such a command, uWSGI will access a file with the name “app.php”, which should contain the function “application”. At the moment, since the plugin is experimental, these names are rigidly defined in the code. Consider the simplest example of PHP code that you can “feed” to this plugin.

     'text/plain'], 'Hello, world!'];

    This example will output the string “Hello, world!” To the browser, while the string “Loading” will be displayed once in the uWSGI vassal log.

    Also popular now: