以下由Laravel教學專欄跟大家介紹Laravel-S高效能,希望對需要的朋友有幫助!
最近公司接了一個基於laravel二開項目,客戶對於高並發要求比較高,傳統的部署laravel項目測試發現已經達到瓶頸,後來發現Laravel-S
可以快速整合式Swoole
到 Laravel
或 Lumen
,然後賦予它們更好的效能於是就試了下,沒想到結果大大出乎我的意料,效能大幅提升,客戶也很滿意。
下面說下具體流程:
1.引入依賴
composer require hhxsv5/laravel-s
2.設定好 .env
檔案
APP_NAME=test APP_ENV=local APP_KEY=base64:QXu20Ct+XlvGEnSmVzrUPXjwGARbb9R6kNo4bj5Ibps= APP_DEBUG=false APP_URL=https://xxx.com/ LOG_CHANNEL=stack DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database DB_USERNAME=root DB_PASSWORD=root BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET= PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" JWT_SECRET=Muw2TYybFUCKxxQLcfwJB6qFMrGbUmP1uYqTCa9g9ziceE3bYz9ePM7eJOw1Reyu
3.發布設定和二進位。這裡有幾點要注意,如果修改了路由或其他設定檔需要清理緩存,重新產生設定快取
php artisan cache:clear php artisan config:cache
發布設定和二進位檔案
php artisan laravels publish
4.執行
php bin/laravels start
5.與nginx配合使用
gzip on; gzip_min_length ; gzip_comp_level ; 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 swoole { # 通过 IP:Port 连接 server weight= max_fails= fail_timeout=30s; # 通过 UnixSocket Stream 连接,小诀窍:将socket文件放在/dev/shm目录下,可获得更好的性能 #server unix:/xxxpath/laravel-s-test/storage/laravels.sock weight= max_fails= fail_timeout=30s; #server weight= max_fails= fail_timeout=30s; #server backup; keepalive ; } server { listen ; # 别忘了绑Host哟 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; } # 当请求PHP文件时直接响应404,防止暴露public/*.php #location ~* \.php$ { # return 404; #} 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://swoole; } }
##
以上是Laravel-S居然能提升這麼高性能!的詳細內容。更多資訊請關注PHP中文網其他相關文章!