下面由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居然能提升这么高性能!的详细内容,更多请关注Work网其它相关文章!