Skip to the content.

tars-server document

Introduction

Tars-server is a basic framework for implementing tars services in PHP. It mainly includes service start and stop, route analysis, protocol processing, and event reporting.

How to use

Tars-server uses composer for package management. Developers only need to perform composer install according to the corresponding version.

For specific usage, please refer to http-server, timer-server, and tcp-server under examples.

Framework description

Tars-server is implemented with swoole as the underlying network transceiver.The framework mainly includes the following directories:

cmd

For the cmd part, contains the following files:

  1. Command.php

    Responsible for specifying the configuration file and startup command when the service starts

  2. CommandBase.php

    Specifies the required implementation of a Command. All such as START are subclasses of CommandBase. It provides the getProcess method to get the currently started service process.

  3. Restart.php

    Restart command, just call stop and then call start

  4. Start.php

Startup command will first analyze the configuration issued by the platform and then introduce the services.php file necessary for the business.

  1. Stop.php The current service stop method is violent. It will pull out all processes according to the service name, and then kill it. Reloading will be introduced later to reload the service code.

core

The core layer is mainly composed of Event, Server, Request, and Response.

Server.php

Responsible for the initialization work before the service starts, including:

After completing the startup of the service, you will enter

Event.php

onReceive method:

onRequest method:

Request.php

Response.php

Responsible for send back package

Service startup process

The service startup is initiated by Start cmd, After the creation of the Server object is called, Then perform the initialization of swoole in turn, After starting the service, you only need to handle the monitoring of onReceive or onRequest.

dependency