Coder Social home page Coder Social logo

runtime's Introduction

PHP Runtimes

In early 2021, Symfony created a "Runtime component". This component may look complex, weird and full of hacks but it is a game changer for how we run PHP applications.

With the Runtime component, we can look at each application as a "black box". A box that has no connection to globals like $_SERVER or $_GET. To run the application you need (you guessed it) a Runtime. It is a class that looks at the black box to figure out what input it requires and handles the output.

Consider this small application that returns an UUID.

namespace Acme;

class Application
{
    public function run() {
        return Uuid::uuid4()->toString();
    }
}

To use this application with the Runtime component we need our front-controller to return a callable that will create the application.

// index.php

return function() {
    return new Acme\Application();
}

If you want to use this application in a CLI environment, you need a Runtime that knows how to run an Acme\Application object and print the output on CLI. If you want to use it with Nginx/PHP-FPM then you need another Runtime that converts the application's output to a HTTP response.

Why is this a good thing?

Since your application is not connected to the global state, it is very portable. It is easy to create a Runtime to run the application with Bref, Swoole or ReactPHP without making any change to the application itself.

Since most modern PHP applications are based on Symfony's HttpKernel, PSR-7 or PSR-15 we don't need too many different runtimes. This organization holds many PHP packages with runtimes for the most popular environments. It is not "the source of all runtimes", but rather a temporary place where runtimes can live before they move in to Bref/Swoole/RoadRunner etc.

All runtimes have hard dependencies to make installation easier. Everything should "just work".

Read more at the Symfony documentation.

Available Runtimes

Bref

Run your application on AWS Lambda with Bref.

Google Cloud

Run your application on Google Cloud.

ReactPHP

Event-driven, non-blocking I/O with ReactPHP.

RoadRunner

Spin up multiple PHP processes with Golang using RoadRunner.

Swoole

Build high-performance, scalable, concurrent HTTP services with Swoole.

PHP-FPM and traditional web servers

These runtimes are for PHP-FPM and the more traditional web servers one might use for local development.

Laravel

A runtime for Laravel and Artisan.

PSR-7 and PSR-15

Use the popular PSR architecture.

Symfony

The runtime for Symfony is included in the runtime component.

Note about sessions

On Symfony < 5.4 session data will not be properly stored when using a "non-traditional" webserver like Bref, Google, ReactPHP, RoadRunner or Swoole. This problem (or missing feature) has been added in Symfony 5.4 and 6.0. You need to use the unreleased version of symfony/http-kernel for sessions to work properly.

Contribute

Contributions are always welcomed. Send your PR or open an issue here: https://github.com/php-runtime/runtime

runtime's People

Contributors

alexander-schranz avatar brettmc avatar cilefen avatar dmerchier avatar eidenschink avatar ferror avatar grahamcampbell avatar leocavalcante avatar mleczakm avatar nyholm avatar ocramius avatar piku235 avatar rickysu avatar sy-records avatar vhenzl avatar

Watchers

 avatar

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.