# php

## Install dependency environment of tarsphp

php7 + swoole2+ is recommended.

## Install php

```
Project: https://github.com/php/php-src
```

## Install swoole

```
Project: https://github.com/swoole/swoole-src
Install via compile: https://wiki.swoole.com/wiki/page/6.html
Install via PECL:
    pecl install swoole
```

## Install tarsphp extension

```
Project: https://github.com/TarsPHP/tars-extension

    Download & Unzip: https://github.com/TarsPHP/tars-extension/archive/master.zip
    cd tars-extension
    sudo phpize
    sudo ./configure
    sudo make
    sudo make install
    add extension = phptars.so in php.ini
```

## TarsPHP Development

### [Quick run tars-http-server](https://github.com/TarsPHP/doc/tree/d80f86da1d0f9b9531efd1fe2bee8415cef8c78b/en/Environment/en/QuickStart/tars-http-server.md)

### Development and packaging

```
The steps of development is same with a litter different between each languages:
1. Write tars file xx.tars;
2. Generate client or server code based on xx.tars by tars conversion tool (statement client or server in configuration, pay attention to the naming convention);
3. develope the logic code (fill in the blanks);
4. Package;
5. Add application information (consistent with the definition of tars) , then upload and publish the package publish through the web management interface.
6. Package will upload to `/data/tars/patchs/tars.upload/`
```

### Publish

```
Code will be published while packaging, and also can be restarted or closed through operation platform.

Package will be uploaded to `/usr/local/app/tars/tarsnode/` in server -- application name + service name, service name PHPTest, service name PHPHttpServer will unzip the code and place it in PHPTest.PHPHttpServer.

Bin, conf, and data folders are placed in each package directory.
-bin: the decompressed program files, and start command file -- tars_start.sh -- and close command file -- tars_stop.sh -- which automatically generates by tars.(you can start/stop service by these two files instead of operation platform).
-conf: the service template configuration, the complete configuration used by service will integrate this file and the configuration which filled in operation platform while publishing.
-data: the cache file of the service information, and the process id file etc.
```

### Log View

```
Log path is `/usr/local/app/tars/app_log/`, such as `/usr/local/app/tars/app_log/PHPTest/PHPHttpServer/PHPTest.PHPHttpServer.log`

Log path of the service is `/usr/local/app/tars/app_log/{service application name}/{service service name}/`, for example, `/usr/local/app/tars/app_log/Test/HelloServer/`

Path pf service executable is `/usr/local/app/tars/tarsnode/data/{service application name}.{service service name}/bin/`, for example: `/usr/local/app/tars/tarsnode/data/Test.HelloServer/bin/`

Path of service template configuration file is `/usr/local/app/tars/tarsnode/data/{service application name}.{service service name}/conf/`, for example: `/usr/local/app/tars/tarsnode/data/Test.HelloServer/conf/`

Path of service cache information file is `/usr/local/app/tars/tarsnode/data/{service application name}.{service service name}/data/`, for example: `/usr/local/app/tars/tarsnode/data/Test.HelloServer/data/`
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tarsphp.gitbook.io/doc/en/environment/php.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
