Laravel經過Swoole提高性能

一、安裝配置laraveljavascript

1.一、composer下載laravelphp

composer create-project --prefer-dist laravel/laravel blog "5.5.*"

1.二、給storage 目錄和 bootstrap/cache 目錄配置讀寫權限css

chmod -R 777 storage chmod -R 777  bootstrap/cache

1.三、配置.env文件的數據庫信息html

DB_HOST=服務器ip DB_DATABASE=數據庫名 DB_USERNAME=用戶名 DB_PASSWORD=密碼

二、安裝配置nginxjava

2.一、安裝nignxnginx

Centos7Yum安裝配置指定版本nginxlaravel

2.二、配置nginxgit

#強制跳轉https
server { listen
80; server_name www.xxxxx.com; rewrite ^(.*) https://$server_name$1 permanent; } server { listen 443; ssl on; server_name www.xxxxx.com; index index.html index.htm index.php; root /usr/share/nginx/html/code/blog/public/; ssl_certificate cert/xxxx.pem; ssl_certificate_key cert/xxxx.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on;
     #優雅連接 location
/ { try_files $uri $uri/ /index.php?$query_string; }      #將php請求交給php-fpm處理 location ~ \.php { fastcgi_index index.php; #fastcgi_pass web_server; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; set $path_info ""; set $real_script_name $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/code/xxxx/public/$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } }

 

三、輸入域名便可看到Laravel歡迎頁面:github

四、編譯安裝Swooleweb

git clone https://github.com/swoole/swoole-src.git && \
cd swoole-src && \ phpize && \ ./configure && \ make && make install

php.ini中添加extension=swoole.so 並重啓php

 五、安裝Laravels拓展包

直接在Laravel項目中集成Swoole,不用改底層代碼

5.一、經過composer安裝Laravels

composer require "hhxsv5/laravel-s:~3.0" -vvv

5.二、Laravel: 修改文件config/app.phpLaravel 5.5+支持包自動發現,可跳過這步

'providers' => [ //...
    Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class, ],

5.三、發佈配置文件(每次升級LaravelS後,建議從新發布一次配置文件

php artisan laravels publish

5.四、修改配置config/laravels.php:監聽的IP、端口等,參考配置項

5.五、啓動Laravels

在運行以前,請先仔細閱讀:注意事項

php artisan laravels  start         //啓動
php artisan laravels  start   -d   //守護進程模式運行

5.六、配置Nginx,由laravels接管php-fpm處理php文件

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 { # 經過 IP:Port 鏈接 server 127.0.0.1:5200 weight=5 max_fails=3 fail_timeout=30s; keepalive 16; } server { listen 80; server_name www.xxxxx.com; rewrite ^(.*) https://$server_name$1 permanent;
 } server { listen 443; ssl on; server_name www.xxxxx.com; index index.html index.htm index.php; root /usr/share/nginx/html/code/blog/public/; ssl_certificate cert/xxx.pem; ssl_certificate_key cert/xxx.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; #關閉目錄瀏覽 autoindex off; # Nginx處理靜態資源(建議開啓gzip),LaravelS處理動態資源。 location / { try_files $uri @laravels; } location @laravels { # proxy_connect_timeout 60s; # proxy_send_timeout 60s; # proxy_read_timeout 120s; proxy_http_version 1.1; proxy_set_header Connection ""; 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;
 } }

 經測試,ab壓測同一個接口,使用Swoole之後提升了兩倍性能

相關文章
相關標籤/搜索