官方链接: https://packagist.org/packages/stone/kernel
 
1. composer安装stone kernel
composer require stone/kernel:dev-master
2. 编辑config/app.php,添加Provider

 
 'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    // 省略很多行

    /*
     * Package Service Providers...
     */
    Stone\StoneServiceProvider::class,

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
],
3. 编辑app/Console/Kernel.php,添加新命令

 
protected $commands = [
    \Stone\Console\Commands\StoneServer::class,
];
4.  Stone的安装已经完成,正常情况下stone:server的命令应该可以正常执行了
 
php ./artisan stone:server --help

Usage:
    stone:server [options]

Options:
      --debug
      --start
      --reload
      --stop
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  A FastCGI server bases on swoole and laravel
5.  下面我们继续,让Server跑起来, 首先需要设定一些server的参数,我们需要新建一个config/stone.php
 
<?php
return [
    'server' => [
        'user' => 'www-data', // 运行用户,一般和php-fpm运行用户相同
        'group' => 'www-data', // 运行组,同上
        'domain' => '/var/run/stone-server-fpm.sock', // unix domain socket地址,用来与nginx进程通信,推荐保持默认即可,如果系统不支持也可以是ip地址
        'port' => 9101, // 端口
        'handler' => 'App\Servers\Handler', // 请求处理器, 一个class名称
        'pid' => '/var/run/stone.pid', // 进程文件
    ]
];
6. 建立Handler, 新建app/Servers/Handler.php

 
<?php namespace App\Servers;

use Stone\Contracts\RequestHandler;
use Response;

class Handler implements RequestHandler
{
    public function process()
    {
        return Response::make('hello, stone server!');
    }

    public function onWorkerStart()
    {    
    }

    public function handleException($e)
    {    
    }
}
7. 启动server, 正常情况下会显示一个ok
 
sudo php ./artisan stone:server --debug
8.配置nginx, 我们把特定的url转发到stone server上来, 让php-fpm和stone共存, 这样方便对比性能, 也可以自由选择是否使用stone server。
 
 
server {

    listen          80;
    server_name  127.0.0.1;

    access_log  /var/log/nginx/stone_access.log;
    error_log   /var/log/nginx/stone_error.log;

    location ~* (^.+\.(example)$)|(.*protected.*|\.git.*) {
        deny all;
    }
    root   /home/stone/stone-demo/public;
    index  index.html index.htm index.php;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location /server/ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_pass unix:/var/run/stone-server-fpm.sock; # Stone
        include fastcgi_params;
    }
}
9. 重启nginx, 访问 http://127.0.0.1/server/
---------------------------------------------------------------------------------------------
不忘初心 方得始终!

唯有志存高远,方能风行天下。

道之所存,虽千万人吾往矣! 情之所钟,虽千万里吾念矣~

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。