PHPackages                             phptars/tars-server - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. phptars/tars-server

ActiveLibrary[Framework](/categories/framework)

phptars/tars-server
===================

tars的php框架

0.7.0(5y ago)1110.9k13[7 issues](https://github.com/TarsPHP/tars-server/issues)4PHPPHP &gt;=5.6

Since Sep 21Pushed 5y ago5 watchersCompare

[ Source](https://github.com/TarsPHP/tars-server)[ Packagist](https://packagist.org/packages/phptars/tars-server)[ RSS](/packages/phptars-tars-server/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (6)Versions (31)Used By (4)

Tars-server documentation
=========================

[](#tars-server-documentation)

Package name: phptars / tar server

Tars is the underlying dependency of PHP server.

How to use
----------

[](#how-to-use)

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

For specific usage, please refer to HTTP server, timer server and TCP server under the corresponding PHP / examples.

Frame description
-----------------

[](#frame-description)

Tars-server is based on the bottom layer of the swoole network transceiver. The framework mainly includes the following directories:

- CMD: responsible for the implementation of the start and stop commands of the framework, and now supports the start, stop and restart commands
- Core: core implementation of framework
- Protocol: responsible for protocol processing

CMD layer

For the CMD layer, it now contains the following files:

1. Command.php:

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

2. CommandBase

It specifies the implementation necessary for a command. All such as start are subclasses of commandbase. Getprocess method is provided to get the currently started service process.

3. Restart

Restart the command, only call the start after the call stops

4. Start

When you start the command, you will first parse the configuration issued by the platform, and then import the services.php file necessary for the business.

Next, monitor whether the process has been started to avoid repeated start-up;

Finally, the configured and predefined swooletable will be passed to the server for service initialization and startup.

5. Stop

The current service stop mode is violent. It will pull out all processes according to the service name, and then kill them. In the future, reload will be introduced to reload the service code.

### Core layer

[](#core-layer)

The core layer is mainly composed of event, server, request and response.

1. Server.php

Be responsible for the initialization of services before startup, including:

- Determine whether it is TCP or HTTP type, register the corresponding callback and start the corresponding server
- Judge if it is timer, it will start the timer scan for the corresponding directory
- Pass through the configuration of swoole
- Register generic callback functions
- Pass the swooletable of the server
- Specify the boot file for the entire framework and force require
- Specify the protocol processing mode of the framework, tar or http

After starting the service, you will first enter onmaster start:

- Name of the write process
- Write PID to file
- Initiate service escalation

onManagerStart:

- Rename process

Next is onworkerstart:

- If it is a TCP type, you need to first convert the comments in the interface to PHP data, which is convenient to handle when routing
- If it is of HTTP type, you need to specify the corresponding namespacename
- Set the name of the corresponding worker
- If it is a timer, you need to start the corresponding timer
- When workerid = 0 (it is guaranteed to trigger only once), submit the service's report task to task

Ontask: submit the appName servername servantname of the service.

You need to pay attention to onReceive and onrequest callbacks respectively.

For the server of TCP, pay attention to onReceive:

- Initialize the request object, pass the SW object into the super global variable $\_server
- Set the protocol to tarsprotocol
- Deal with the protocol and return the package
- Clear global variables

For HTTP servers, focus on onrequest:

- Processing cookie, get, post request parameters
- Initialize the request object, pass the SW object into the super global variable $\_server
- Deal with the protocol and return the package
- Clear global variables

2. Event.php

OnReceive method:

- The request of TCP protocol will first enter the route method of tarsprotocol for routing
- After routing, make the actual function call
- Pack back
- Send back package

Onrequest method:

- Provide a default probe interface
- Perform basic routing protocol analysis
- Call the corresponding controller method
- Send back package

3. Request.php

Store some necessary request data;

Set and remove global variables

4. Response.php

Responsible for some work of returning package

### Service startup process

[](#service-startup-process)

The start of the whole service is initiated by start under CMD,

After that, we call the creation of the Server object.

Then, initialize swoole in turn,

After starting the service, you only need to process the onReceive or onrequest listening

Framework dependency
--------------------

[](#framework-dependency)

The framework relies on the following packages:

- Phptars / tar client: making calls to the tar service
- Phptars / tar report: responsible for reporting the running status of the service itself
- Phptars / tar config: responsible for pulling configuration uploaded by the platform

Changelog

### v0.7.0(2021-03-17)

[](#v0702021-03-17)

- del require of LumenRoute &amp; Monolog
- use new version tarslog

### v0.6.0(2020-07-07)

[](#v0602020-07-07)

- Support json version
- Support tars gateway

### v0.5.0(2020-09-08)

[](#v0502020-09-08)

### v0.4.0(2019-07-16)

[](#v0402019-07-16)

-Support for protobuf

### v0.3.1(2019-06-21)

[](#v0312019-06-21)

-Support for multiple servants

-Using swoole addListener as the underlying support

-Support one service to deploy multiple objs, using the tars or HTTP protocol respectively

-Adjust the format of services.php to return a two-dimensional array with objname as the key.

-Protocolname, servertype, istimer are not read from the private template, they need to be specified in services.php

-Fix support for websocket by multi servant

### v0.2.4(2019-03-20)

[](#v0242019-03-20)

-Format code according to PSR rules

-Fix bugs in code

-Support custom master cache

-Open access to swoole objects

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance7

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~43 days

Recently: every ~147 days

Total

22

Last Release

1932d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bf1b3ee26ddb9ebe4490a8f1bcd84a7450fa70cf0bf367fd6c267ba7d353d3fd?d=identicon)[phptars](/maintainers/phptars)

---

Top Contributors

[![meijing0114](https://avatars.githubusercontent.com/u/2072584?v=4)](https://github.com/meijing0114 "meijing0114 (14 commits)")[![bobzhangyong](https://avatars.githubusercontent.com/u/4799677?v=4)](https://github.com/bobzhangyong "bobzhangyong (13 commits)")[![copyrenzhe](https://avatars.githubusercontent.com/u/2667735?v=4)](https://github.com/copyrenzhe "copyrenzhe (9 commits)")[![wodetian55](https://avatars.githubusercontent.com/u/17988141?v=4)](https://github.com/wodetian55 "wodetian55 (3 commits)")[![dpp2009](https://avatars.githubusercontent.com/u/5278911?v=4)](https://github.com/dpp2009 "dpp2009 (2 commits)")[![tookly](https://avatars.githubusercontent.com/u/10864122?v=4)](https://github.com/tookly "tookly (1 commits)")

### Embed Badge

![Health badge](/badges/phptars-tars-server/health.svg)

```
[![Health](https://phpackages.com/badges/phptars-tars-server/health.svg)](https://phpackages.com/packages/phptars-tars-server)
```

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M293](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
