PHP Microservice Framework: entorno de desarrollo para Swoft


Introduccion


ΒΏQuΓ© es swoft?


Swoft es un marco de trabajo de rutina de microservicio de alto rendimiento de PHP. Se ha publicado durante muchos aΓ±os y se ha convertido en la mejor opciΓ³n para php. Puede ser como Go, un servidor web de rutina incorporado y un cliente de rutina comΓΊn y reside en la memoria, independiente del PHP-FPM tradicional. Existen operaciones de lenguaje Go similares, similares a las anotaciones flexibles del marco Spring Cloud.


A travΓ©s de tres aΓ±os de acumulaciΓ³n y exploraciΓ³n de direcciones, Swoft ha convertido a Swoft en la Nube de Primavera en el mundo PHP, que es la mejor opciΓ³n para el marco de trabajo de alto rendimiento y la gestiΓ³n de microservicios de PHP.


Sobre tutorial


Escribo un artΓ­culo de Learn Swoft , puede ayudar a alguien a aprender fΓ‘cilmente


Github


Si tiene algunos problemas, puede enviar el problema por github.


https://github.com/swoft-cloud/swoft


Discutir


Puedes discutir el problema aquΓ­.


Discutir comunidad


Tutorial


Requisitos


  • Centos7 +
  • PHP Composer
  • Docker-ce
  • Docker-compose

Instalar requisitos


Docker-ce en centos


udo yum install -y yum-utils \device-mapper-persistent-data \lvm2 sudo yum-config-manager \--add-repo \https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo sudo yum makecache fast sudo yum install docker-ce sudo systemctl enable docker sudo systemctl start docker sudo usermod -aG docker $USER newgrp - docker sudo systemctl restart docker 

Docker-compose


 su root curl -L https://get.daocloud.io/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose 

Php


 su root rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum -y install php71w-fpm 

Compositor


 su root curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer 

Uso


Crear proyecto:


 composer create-project swoft/swoft Swoft 

Estructura del proyecto:


 β”œβ”€β”€ app/ ----- root directory β”‚ β”œβ”€β”€ Annotation/ ----- annotation β”‚ β”œβ”€β”€ Aspect/ ----- aop β”‚ β”œβ”€β”€ Common/ ----- common util β”‚ β”œβ”€β”€ Console/ ----- command β”‚ β”œβ”€β”€ Exception/ ----- exception β”‚ β”‚ └── Handler/ ----- exception handler β”‚ β”œβ”€β”€ Http/ ----- HTTP Demo β”‚ β”‚ β”œβ”€β”€ Controller/ β”‚ β”‚ └── Middleware/ β”‚ β”œβ”€β”€ Helper/ ----- helper β”‚ β”œβ”€β”€ Listener/ ----- listener β”‚ β”œβ”€β”€ Model/ β”‚ β”‚ β”œβ”€β”€ Dao/ β”‚ β”‚ β”œβ”€β”€ Data/ β”‚ β”‚ β”œβ”€β”€ Logic/ β”‚ β”‚ └── Entity/ β”‚ β”œβ”€β”€ Rpc/ ----- RPC Demo β”‚ β”‚ └── Service/ β”‚ β”‚ └── Middleware/ β”‚ β”œβ”€β”€ WebSocket/ ----- WebSocket Demo β”‚ β”‚ β”œβ”€β”€ Chat/ β”‚ β”‚ β”œβ”€β”€ Middleware/ β”‚ β”‚ └── ChatModule.php β”‚ β”œβ”€β”€ Tcp/ ----- TCP Demo β”‚ β”‚ └── Controller/ β”‚ β”œβ”€β”€ Application.php ----- Application β”‚ β”œβ”€β”€ AutoLoader.php ----- Autoloader β”‚ └── bean.php β”œβ”€β”€ bin/ β”‚ β”œβ”€β”€ bootstrap.php β”‚ └── swoft ----- entry file β”œβ”€β”€ config/ ----- config directory β”‚ β”œβ”€β”€ base.php β”‚ └── db.php β”œβ”€β”€ public/ ----- public directory β”œβ”€β”€ resource/ ----- resource directory β”‚ β”œβ”€β”€ language/ β”‚ └── view/ β”œβ”€β”€ runtime/ ----- runtime directory β”œβ”€β”€ test/ ----- unit directory β”‚ └── bootstrap.php β”œβ”€β”€ composer.json β”œβ”€β”€ phar.build.inc └── phpunit.xml.dist β”œβ”€β”€ .env ----- env config β”œβ”€β”€ docker-compose.yml └── phpunit.xml.dist 

Upate docker-compose.yaml:


 version: "3" services: redis: image: redis:alpine container_name: redis ports: - 6379:6379 volumes: - redisdb:/data - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime swoft: image: swoft/swoft # for local develop command: php -S 127.0.0.1:13300 container_name: swoft-test environment: - APP_ENV=dev - TIMEZONE=Asia/Shanghai ports: - "18306:18306" - "18307:18307" - "18308:18308" volumes: - ./:/var/www/swoft mysql: image: mysql container_name: mysql-srv environment: - MYSQL_ROOT_PASSWORD=123456 ports: - "3306:3306" volumes: - mysqldb:/var/lib/mysql volumes: redisdb: mysqldb: 

Comience swoft por Docker componer:


 docker-compose up -d 

Haga clic en http://127.0.0.1:18306 , verΓ‘ la siguiente pΓ‘gina.



Github


Si tiene algunos problemas, puede enviar el problema por github.


https://github.com/swoft-cloud/swoft


Discutir


Puedes discutir el problema aquΓ­.


Discutir comunidad

Source: https://habr.com/ru/post/480904/


All Articles