laravels -- Swoole加速php

  LaravelS是一個膠水項目,用於快速集成SwooleLaravel,而後賦予它們更好的性能、更多可能性.javascript

  環境 : ubuntu16 + nginx + php7.1 + LaravelS搭建高性能php服務器。php

依賴 說明
PHP >= 5.5.9
Swoole >= 1.7.19 推薦最新的穩定版 從2.0.12開始再也不支持PHP5
Laravel/Lumen >= 5.1
Gzip[可選的] zlib,用於壓縮HTTP響應,檢查本機libz是否可用 ldconfig -p|grep libz
Inotify[可選的] inotify,用於修改代碼後自動Reload Worker進程,檢查本機inotify是否可用 php --ri inotify

 

1:環境監測
 
php -v   (檢查php)    
cc -v   (檢查 gcc)
openssl version   (檢查openssl)
php --ri swoole   (檢查 swoole)

 

2:安裝swoolecss

sudo wget https://github.com/swoole/swoole-src/archive/v4.0.4.zip
sudo  unzip v4.0.4.zip

*** 若是沒有unzip,先安裝    sudo apt install unzip   再  sudo  unzip v4.0.4.zip

cd swoole-src-4.0.4    (進入解壓包)
sudo phpize

***若是沒有phpize  先安裝  sudo apt-get install php7.1-dev  再    sudo phpize

sudo ./configure
sudo make
sudo make install

 

安裝成功後,在php中加入so
位置  /etc/php/7/1/cli/php.ini
添加配置   extension=swoole.so

檢查版本   php --ri swoole

 

3:安裝laravelshtml

  注:若尚未 Laravel 環境請參考   https://www.cnblogs.com/cj8988/p/9454142.htmljava

一、在你的Laravel/Lumen項目的根目錄下執行
    composer require "hhxsv5/laravel-s:~3.0" -vvv

二、註冊Service Provider
  Laravel: 修改文件config/app.php,Laravel 5.5+支持包自動發現,你應該跳過這步
  'providers' => [
            Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class,
        ],

三、發佈配置文件,每次升級LaravelS後,建議從新發布一次配置文件 php artisan laravels publish 四、.修改配置config/laravels.php:監聽的IP、端口等。
五、運行   php artisan laravels {start|stop|restart|reload|publish}
命令 說明
start 啓動LaravelS,展現已啓動的進程列表 ps -ef|grep laravels
stop 中止LaravelS
restart 重啓LaravelS
reload 平滑重啓全部worker進程,這些worker進程內包含你的業務代碼和框架(Laravel/Lumen)代碼,不會重啓master/manger進程
publish 發佈配置文件到你的項目中config/laravels.php

 

四、配置nginxnginx

在   nginx.conf  配置中添加

gzip on;
gzip_min_length 1024;
gzip_comp_level 2;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml;
gzip_vary on;
gzip_disable "msie6";

 upstream laravels { # By IP:Port server 127.0.0.1:5200 weight=5 max_fails=3 fail_timeout=30s; }
在service配置中添加

server {
    listen 80;
    server_name laravels.com;
    root /xxxpath/laravel-s-test/public;
    access_log /yyypath/log/nginx/$server_name.access.log  main;
    autoindex off;
    index index.html index.htm;
    # Nginx處理靜態資源(建議開啓gzip),LaravelS處理動態資源。
    location / {
        try_files $uri @laravels;
    }
location @laravels { proxy_http_version 1.1; proxy_set_header Connection "keep-alive"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-PORT $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Scheme $scheme; proxy_set_header Server-Protocol $server_protocol; proxy_set_header Server-Name $server_name; proxy_set_header Server-Addr $server_addr; proxy_set_header Server-Port $server_port; proxy_pass http://laravels; } }

 

參考文檔   https://laravel-china.org/articles/8050/laravels-speed-up-laravellumen-through-swoolelaravel

       https://github.com/hhxsv5/laravel-sgit

相關文章
相關標籤/搜索