GithubHelp home page GithubHelp logo

stone's Introduction

Laravel Stone - HTTP server using the ReactPHP

With ReactPHP we keep our application alive between requests so we only execute this bootstrap once when starting the server: the footprint is absent from Requests. However now the tables are turned: we're vulnerable to memory consumption, fatal error, statefulness and code update worries.

Installation

Installer using Composer:

$ composer require tabuna/stone

Example

The easiest way to run:

$ php vendor/bin/stone

You can also specify a port:

$ php vendor/bin/stone -p 8000

It does not interfere with your application, so do not worry

Making production ready

Supervisord

Install Supervisord

$ sudo apt-get install -y supervisor

Here's a configuration example (create a *.conf file in /etc/supervisord/conf.d):

[program:laravel-stone-server]
command=php /path/to/your/code/vendor/bin/stone -p 800%(process_num)
process_name=%(program_name)s-%(process_num)d
numprocs=4
umask=022
user=foobar
stdout_logfile=/var/log/supervisord/%(program_name)s-%(process_num)d.log              ; stdout log path, NONE for none; default AUTO
stderr_logfile=/var/log/supervisord/%(program_name)s-%(process_num)d-error.log        ; stderr log path, NONE for none; default AUTO
autostart=true
autorestart=true
startretries=3

It will:

  • run 4 servers on ports 8000, 8001, 8002 and 8003
  • it restarts them automatically when they crash (will try a maximum of 3 times, then give up)

Nginx as Load-Balancer

What we do here is to proxy only requests that don’t point to a local file.

upstream stone  {
    server 127.0.0.1:8000;
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;
    server 127.0.0.1:8003;
}


server {
    listen 80;
    server_name example.com;
    root /example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        proxy_pass http://stone;
        break;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Donate & Support

If you would like to support development by making a donation you can do so here. 😊

License

The MIT License (MIT). Please see License File for more information.

stone's People

Contributors

tabuna avatar

Watchers

 avatar  avatar  avatar

Forkers

x12311231

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.