PHP Microservice Framework: Development Environment for Swoft

  • Tutorial


Introduction


What is Swoft?


Swoft is a PHP high performance microservice coroutine framework. It has been published for many years and has become the best choice for php. It can be like Go, built-in coroutine web server and common coroutine client and is resident in memory, independent of traditional PHP-FPM. There are similar Go language operations, similar to the Spring Cloud framework flexible annotations.


Through three years of accumulation and direction exploration, Swoft has made Swoft the Spring Cloud in the PHP world, which is the best choice for PHP's high-performance framework and microservices management.


About tutorial


I write article by learn Swoft ,it can help someone to easy to learn swoft


Github


If you have some problems, you can submit issue by github.


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


Discuss


You can discuss problem in here.


Discuss community


Tutorial


Requirements


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

Install Requirements


Docker-ce on 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

Composer


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

Usage


Create project:


composer create-project swoft/swoft Swoft

Project struct:


├── 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:

Start swoft by Docker compose:


docker-compose up -d

You click http://127.0.0.1:18306, will see the following page.



Github


If you have some problems, you can submit issue by github.


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


Discuss


You can discuss problem in here.


Discuss community

Share post
AdBlock has stolen the banner, but banners are not teeth — they will be back

More
Ads

Comments 0

Only users with full accounts can post comments. Log in, please.