前言:最近想使用swoole 試試websocket,正好安裝測試下laravel 和swoole 性能,不知道是不是laravel9 性能優化的好,最後壓測結果和laravels 的差不多~
#Laradock 安裝swoole
#動手操作後遇到問題:
laravel影片教學】
驗證結果:設定laravels 的http 伺服器
1. 安裝laravel 專案教學很多,這裡參考自:基於安裝了docker 的環境
curl -s "https://laravel.build/laravel9" | bashCopy2. 安裝laravels
composer require hhxsv5/laravel-sCopy3. 發布laravels 設定
php artisan laravels publishCopy4.設定網站說明: 網站對應的專案程式碼都是/var/www/laravel9/public(1) 設定laravels 的http 伺服器
upstream laravels { # Connect IP:Port server workspace:5200 weight=5 max_fails=3 fail_timeout=30s; keepalive 16; } server { listen 80; server_name swoole.test; root /var/www/laravel9/public; index index.php index.html index.htm; # Nginx 处理静态资源,LaravelS 处理动态资源 location / { try_files $uri @laravels; } location @laravels { 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; } error_log /var/log/nginx/swoole_test_error.log; access_log /var/log/nginx/swoole_test_access.log; }#注意:laravels 項目需要在laravel9 專案下的.env 檔案中增加以下設定:
LARAVELS_LISTEN_IP=workspace LARAVELS_DAEMONIZE=trueCopy(2) 設定普通laravel 專案網站
server { listen 80; listen [::]:80; # For https # listen 443 ssl; # listen [::]:443 ssl ipv6only=on; # ssl_certificate /etc/nginx/ssl/default.crt; # ssl_certificate_key /etc/nginx/ssl/default.key; server_name laravel.test; root /var/www/laravel9/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fixes timeouts fastcgi_read_timeout 600; include fastcgi_params; } location ~ /\.ht { deny all; } location /.well-known/acme-challenge/ { root /var/www/letsencrypt/; log_not_found off; } error_log /var/log/nginx/laravel_error.log; access_log /var/log/nginx/laravel_access.log; }(3) 本機host 設定
127.0.0.1 swoole.test127.0.0.1 laravel.testCopy(4) 重新build 容器
docker-compose stop docker-compose build workspace nginx docker-compose up -d redis mysql nginx workspaceCopy(5) 進入workspace 容器啟動laravels
進入容器指令:
docker exec -it d4940755a928 /bin/bashCopy
#AB 效能測試結果
以上是laravel9 和 laravels 性能大比拼!的詳細內容。更多資訊請關注PHP中文網其他相關文章!