您好,登錄后才能下訂單哦!
小編給大家分享一下Laravel-S怎么提升性能,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
最近公司接了一個(gè)基于laravel二開(kāi)項(xiàng)目,客戶(hù)對(duì)于高并發(fā)要求比較高,傳統(tǒng)的部署laravel項(xiàng)目測(cè)試發(fā)現(xiàn)已經(jīng)達(dá)到瓶頸,后來(lái)發(fā)現(xiàn) Laravel-S
可以快速集成 Swoole
到 Laravel
或 Lumen
,然后賦予它們更好的性能于是就試了下,沒(méi)想到結(jié)果大大出乎我的意料,性能大幅度提升,客戶(hù)也很滿(mǎn)意。
下面說(shuō)下具體流程:
1.引入依賴(lài)
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.發(fā)布配置和二進(jìn)制文件。這里有幾點(diǎn)要注意,如果修改了路由或者其他配置文件需要清理緩存,重新生成配置緩存
php artisan cache:clear php artisan config:cache
發(fā)布配置和二進(jìn)制文件
php artisan laravels publish
4.運(yùn)行
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 { # 通過(guò) IP:Port 連接 server weight= max_fails= fail_timeout=30s; # 通過(guò) 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處理靜態(tài)資源(建議開(kāi)啟gzip),LaravelS處理動(dòng)態(tài)資源。 location / { try_files $uri @laravels; } # 當(dāng)請(qǐng)求PHP文件時(shí)直接響應(yīng)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; } }
看完了這篇文章,相信你對(duì)“Laravel-S怎么提升性能”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。