scripts Store the scripts required by the business, such as tars2php.sh, which is responsible for generating the code required by the client based on the tars file
src The directory where the business logic is located mainly contains the following structure:
<tars>
<application>
...
<client>
...
</client>
<server>
...
protocolName=http
</server>
</application>
</tars>
Just add it in :
protocolName=http
<tars>
<application>
<client>
</client>
<server>
protocolName=http
</server>
</application>
</tars>
{
"name" : "tars-http-server-demo",
"description": "tars http server",
"require": {
"phptars/tars-server": "~0.2",
"phptars/tars-deploy": "~0.1",
"phptars/tars2php": "~0.1",
"phptars/tars-log": "~0.1",
"ext-zip" : ">=0.0.1"
},
"autoload": {
"psr-4": {
"HttpServer\\" : "./"
}
},
"minimum-stability": "stable",
"scripts" : {
"deploy" : "\\Tars\\deploy\\Deploy::run"
}
}
The psr-4 in name, description, and autoload can be modified to what you need. Here we take this as an example.
<?php
require_once(__DIR__."/vendor/autoload.php");
use \Tars\cmd\Command;
//php tarsCmd.php conf restart
$config_path = $argv[1];
$pos = strpos($config_path,"--config=");
$config_path = substr($config_path,$pos+9);
$cmd = strtolower($argv[2]);
$class = new Command($cmd,$config_path);
$class->run();
This file is responsible for startup and entry loading 5. Create a new services.php file with the following content:
<?php
// Load the code in namespace mode under the framework of psr4
return [
'obj' => [
'namespaceName' => 'HttpServer\\',
'saveTarsConfigFileDir' => 'src/conf/', //File save directory pulled from tarsconfig, Default is src/conf
'saveTarsConfigFileName' => [ '',], //The name of the file that needs to be pulled from tarsconfig. Configure on the web
'monitorStoreConf' => [
//Use redis to cache main report information
//'className' => Tars\monitor\cache\RedisStoreCache::class,
//'config' => [
// 'host' => '127.0.0.1',
// 'port' => 6379,
// 'password' => ':'
//],
//Use swoole_table to cache the main report information (default)
'className' => Tars\monitor\cache\SwooleTableStoreCache::class,
'config' => [
'size' => 40960
]
],
'registryStoreConf' => [
'className' => Tars\registry\RouteTable::class,
'config' => [
'size' => 200
]
],
'protocolName' => 'http', //http, json, tars or other
'serverType' => 'http', //http(no_tars default), websocket, tcp(tars default), udp
],
];
namespaceName is the namespace name actually used by the business and must correspond to the configuration in composer.json monitorStoreConf Storage configuration for the main report information
- className is the class name of the storage implementation class for the main report information. The default is \Tars\monitor\cache\SwooleTableStoreCache::class Use swoole_table storage, and tars-monitor also provides the redis storage method. Users can also customize new implementations, but must implement the \Tars\monitor\contract\StoreCacheInterface interface - config is the configuration information of the implementation class that stores the main report information. It is passed as a parameter when the implementation class is initialized. The default value corresponds to the size of swoole_table.
<?php
return array(
'appName' => 'PHPTest',
'serverName' => 'PHPHttpServer',
'objName' => 'obj',
);
This name must correspond exactly to the name on the tars platform.
<?php
return array(
'appName' => 'PHPTest',
'serverName' => 'PHPServer',
'objName' => 'obj',
'withServant' => false,//choose servant / client to generate automatically
'tarsFiles' => array(
'./example.tars'
),
'dstPath' => '../src/servant',
'namespacePrefix' => 'HttpServer\servant',
);
APPName, serverName, objName must be exactly the same as those applied on the tars platform. withServant must be false, and specify the path of tarsFiles.
dstPath is generally ../ src /?
, here is ../ src / servant
, so the generated code will go to this folder.
namespacePrefix is the namespace of the code, here is HttpServer \ servant
, which also corresponds to the name of psr-4 in composer.json.
cd ../tars/
php ../src/vendor/phptars/tars2php/src/tars2php.php ./tarsclient.proto.php
Here is PHPTest/PHPServer/obj - classes folder - stores files generated by structs in tars - tars folder - stores tars files - TestTafServiceServant.php - the actual remote rpc call file
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。