Do not speak Portuguese? Translate this site with Google or Bing Translator
Laravel Octane Swoole em ambiente Laravel Sail

Posted on: April 05, 2023 03:37 PM

Posted by: Renato

Views: 927

Laravel Octane Swoole em ambiente Laravel Sail - Tutorial Passo a Passo para Configuração

#laravel #phpswoole #laraveloctane

Laravel Sail with HTTPS Swoole

0. Crie seu projeto Laravel

cd ~/codecurl -s https://laravel.build/test-project | bashcd test-projectsail up -d

1. Install Laravel Octane

Install the Laravel Octane with

sail composer require laravel/octane

and then

sail artisan octane:install
Select 1 for swoole

Use code . command open the VS Code.

1.1 Octane Config File

✏️ Append/Edit in config/octane.php file

 

/*
  |--------------------------------------------------------------------------
  | Octane Swoole Configuration Options
  |--------------------------------------------------------------------------
  |
  | While using Swoole, you may define additional configuration options as
  | required by the application. You maycheck which options you need from:
  | https://www.swoole.co.uk/docs/modules/swoole-server/configuration
  |
  */
   
  'swoole' => [
  'ssl' => true,
  'options' => [
  'ssl_cert_file' => '/etc/swoole/ssl/certs/sail-selfsigned.crt',
  'ssl_key_file' => '/etc/swoole/ssl/private/sail-selfsigned.key',
  ]
  ],

2. Configuração do arquivo ENV

OCTANE_SERVER=swoole
OCTANE_HTTPS=true  

3. Mantenha o Swoole funcionando

sail artisan sail:publish
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=swoole --host=0.0.0.0 --port=8000 --watch
sail npm install --save-dev chokidar

4. Configuração do Docker

ports:
  - '${APP_PORT:-80}:80'
  - 8000:8000
FROM ubuntu:21.04
   
  LABEL maintainer="Taylor Otwell"
   
  ARG WWWGROUP
   
  WORKDIR /var/www/html
   
  ENV DEBIAN_FRONTEND noninteractive
  ENV TZ=UTC
   
  RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
   
  RUN apt-get update \
  && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
  && mkdir -p ~/.gnupg \
  && chmod 600 ~/.gnupg \
  && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
  && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
  && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
  && echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu hirsute main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
  && apt-get update \
  && apt-get install -y php8.0-cli php8.0-dev \
  php8.0-pgsql php8.0-sqlite3 php8.0-gd \
  php8.0-curl php8.0-memcached \
  php8.0-imap php8.0-mysql php8.0-mbstring \
  php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
  php8.0-intl php8.0-readline php8.0-pcov \
  php8.0-msgpack php8.0-igbinary php8.0-ldap \
  php8.0-redis php8.0-swoole \
  && php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
  && curl -sL https://deb.nodesource.com/setup_16.x | bash - \
  && apt-get install -y nodejs \
  && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
  && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
  && apt-get update \
  && apt-get install -y yarn \
  && apt-get install -y mysql-client \
  && apt-get install -y postgresql-client \
  && apt-get -y autoremove \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
   
  RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
   
  RUN groupadd --force -g $WWWGROUP sail
  RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
   
  RUN mkdir -p /etc/swoole/ssl/certs/ /etc/swoole/ssl/private/
  RUN openssl req -x509 -nodes -days 365 -subj "/C=CA/ST=QC/O=Artisan, Inc./CN=localhost" \
  -addext "subjectAltName=DNS:localhost" -newkey rsa:2048 \
  -keyout /etc/swoole/ssl/private/sail-selfsigned.key \
  -out /etc/swoole/ssl/certs/sail-selfsigned.crt;
  RUN chmod 644 /etc/swoole/ssl/certs/*.crt
  RUN chown -R root:sail /etc/swoole/ssl/private/
  RUN chmod 640 /etc/swoole/ssl/private/*.key
   
  COPY start-container /usr/local/bin/start-container
  COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
  COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
  RUN chmod +x /usr/local/bin/start-container
   
  EXPOSE 8000
   
  ENTRYPOINT ["start-container"]

5. Recrie o contêiner

sail build --no-cache

6. Teste

sail artisan octane:status

e também abrir o navegador e entrar https://localhost:8000, deve abrir a página de boas-vindas de Laravel com HTTPS.

Também faço o teste usando ab, para saber quanto ganho de desempenho.

ab -n 10000 -c 512 -H "Accept-Encoding: gzip, deflate" https://localhost:8000/

Result:

Server Software:        swoole-http-server
Server Hostname:        localhost
Server Port:            8000
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
Server Temp Key:        X25519 253 bits
TLS Server Name:        localhostDocument Path:          /
Document Length:        17503 bytesConcurrency Level:      512
Time taken for tests:   97.184 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      185930000 bytes
HTML transferred:       175030000 bytes
Requests per second:    102.90 [#/sec] (mean)
Time per request:       4975.846 [ms] (mean)
Time per request:       9.718 [ms] (mean, across all concurrent requests)
Transfer rate:          1868.33 [Kbytes/sec] receivedConnection Times (ms)
              min  mean[+/-sd] median   max
Connect:        2   30  96.9      3     633
Processing:    56 4794 2417.4   4598   19666
Waiting:       17 4791 2418.0   4586   19665
Total:         60 4824 2403.2   4613   19668Percentage of the requests served within a certain time (ms)
  50%   4613
  66%   5592
  75%   6085
  80%   6398
  90%   7509
  95%   8599
  98%  10384
  99%  12929
 100%  19668 (longest request)

As the baseline: the default PHP built-in server

ab -n 10000 -c 512 -H "Accept-Encoding: gzip, deflate" http://localhost/

Result:

Server Software:
Server Hostname:        localhost
Server Port:            80Document Path:          /
Document Length:        17490 bytesConcurrency Level:      512
Time taken for tests:   198.809 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      186310000 bytes
HTML transferred:       174900000 bytes
Requests per second:    50.30 [#/sec] (mean)
Time per request:       10179.014 [ms] (mean)
Time per request:       19.881 [ms] (mean, across all concurrent requests)
Transfer rate:          915.17 [Kbytes/sec] receivedConnection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.4      0       9
Processing:    26 9913 1863.2  10041   13891
Waiting:       15 9912 1863.2  10041   13890
Total:         28 9913 1862.1  10041   13891Percentage of the requests served within a certain time (ms)
  50%  10041
  66%  10549
  75%  11006
  80%  11085
  90%  11833
  95%  12221
  98%  12640
  99%  13391
 100%  13891 (longest request)

Conclude the results


3

Share

Donate to Site


About Author

Renato

Developer

Add a Comment
Comments 1 Comments
  • Renato Lucena
    Renato Lucena - há 10 meses
    => https://gist.github.com/lucenarenato/95ee3b6b8c16907dd6ee5a415475eb55

Blog Search


Categories

OUTROS (15) Variados (109) PHP (127) Laravel (154) Black Hat (3) front-end (28) linux (110) postgresql (37) Docker (25) rest (5) soap (1) webservice (6) October (1) CMS (2) node (7) backend (13) ubuntu (54) devops (25) nodejs (5) npm (2) nvm (1) git (8) firefox (1) react (6) reactnative (5) collections (1) javascript (6) reactjs (7) yarn (0) adb (1) Solid (2) blade (3) models (1) controllers (0) log (0) html (2) hardware (3) aws (14) Transcribe (2) transcription (1) google (4) ibm (1) nuance (1) PHP Swoole (5) mysql (28) macox (4) flutter (1) symfony (1) cor (1) colors (2) homeOffice (2) jobs (3) imagick (2) ec2 (1) sw (1) websocket (1) markdown (1) ckeditor (1) tecnologia (14) faceapp (1) eloquent (14) query (3) sql (36) ddd (3) nginx (9) apache (4) certbot (1) lets-encrypt (3) debian (11) liquid (1) magento (2) ruby (1) LETSENCRYPT (1) Fibonacci (1) wine (1) transaction (1) pendrive (1) boot (1) usb (1) prf (1) policia (2) federal (1) lucena (1) mongodb (4) paypal (1) payment (1) zend (1) vim (3) ciencia (6) js (1) nosql (1) java (1) JasperReports (1) phpjasper (1) covid19 (1) saude (1) athena (1) cinnamon (1) phpunit (2) binaural (1) mysqli (3) database (37) windows (6) vala (1) json (2) oracle (1) mariadb (4) dev (12) webdev (24) s3 (4) storage (1) kitematic (1) gnome (2) web (2) intel (3) piada (1) cron (2) dba (13) lumen (1) ffmpeg (2) android (2) aplicativo (1) fedora (2) shell (4) bash (3) script (3) lider (1) htm (1) csv (1) dropbox (1) db (3) combustivel (2) haru (1) presenter (1) gasolina (1) MeioAmbiente (1) Grunt (1) biologia (1) programming (21) performance (3) brain (1) smartphones (1) telefonia (1) privacidade (1) opensource (3) microg (1) iode (1) ssh (3) zsh (2) terminal (3) dracula (1) spaceship (1) mac (2) idiomas (1) laptop (2) developer (36) api (4) data (1) matematica (1) seguranca (2) 100DaysOfCode (9) hotfix (1) documentation (1) laravelphp (9) RabbitMQ (1) Elasticsearch (1) redis (2) Raspberry (4) Padrao de design (4) JQuery (1) angularjs (4) Dicas (36) Kubernetes (2) vscode (2) backup (1) angular (3) servers (2) pipelines (1) AppSec (1) DevSecOps (4) rust (1) RustLang (1) Mozilla (1) algoritimo (1) sqlite (1) Passport (1) jwt (4) security (2) translate (1) kube (1) iot (1) politica (2) bolsonaro (1) flow (1) podcast (1) Brasil (1) containers (2) traefik (1) networking (1) host (1) POO (2) microservices (2) bug (1) cqrs (1) arquitetura (2) Architecture (3) sail (3) militar (1) artigo (1) economia (1) forcas armadas (1) ffaa (1) autenticacao (1) autorizacao (2) authentication (4) authorization (2) NoCookies (1) wsl (4) memcached (1) macos (2) unix (2) kali-linux (1) linux-tools (5) apple (1) noticias (2) composer (1) rancher (1) k8s (1) escopos (1) orm (1) jenkins (4) github (5) gitlab (3) queue (1) Passwordless (1) sonarqube (1) phpswoole (1) laraveloctane (1) Swoole (1) Swoole (1) octane (1) Structurizr (1) Diagramas (1) c4 (1) c4-models (1) compactar (1) compression (1) messaging (1) restfull (1) eventdrive (1) services (1) http (1) Monolith (1) microservice (1) historia (1) educacao (1) cavalotroia (1) OOD (0) odd (1) chatgpt (1) openai (3) vicuna (1) llama (1) gpt (1) transformers (1) pytorch (1) tensorflow (1) akitando (1) ia (1) nvidia (1) agi (1) guard (1) multiple_authen (2) rpi (1) auth (1) auth (1) auth (1) auth (1) Oh My Zsh (1) Manjaro (1) BigLinux (2) ArchLinux (1) Migration (1) Error (1) Monitor (1) Filament (1) LaravelFilament (1) replication (1) phpfpm (1) cache (1) vpn (1) l2tp (1) zorin-os (1) optimization (1) scheduling (1) monitoring (1) linkedin (1) community (1) inteligencia-artificial (2) wsl2 (1) maps (1) API_KEY_GOOGLE_MAPS (1)

New Articles



Get Latest Updates by Email