Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 422ab73

Browse files
author
李宏涛
committed
reorganize php sample codes
1 parent 262c2d5 commit 422ab73

File tree

36 files changed

+74
-2012
lines changed

36 files changed

+74
-2012
lines changed
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
{
2-
"name" : "tars-http-server-demo",
3-
"description": "tars http server",
4-
"require": {
5-
"phptars/tars-server": "~0.3",
6-
"phptars/tars-deploy": "~0.1",
7-
"phptars/tars2php": "~0.1",
8-
"phptars/tars-log": "~0.1",
9-
"ext-zip" : ">=0.0.1"
10-
},
11-
"autoload": {
12-
"psr-4": {
13-
"HttpServer\\" : "./"
14-
}
15-
},
16-
"minimum-stability": "stable",
17-
"scripts" : {
18-
"deploy" : "\\Tars\\deploy\\Deploy::run"
2+
"name": "tars-http-server-demo",
3+
"description": "tars http server",
4+
"require": {
5+
"phptars/tars-server": "~0.3",
6+
"phptars/tars-deploy": "~0.1",
7+
"phptars/tars2php": "~0.1",
8+
"phptars/tars-log": "~0.1",
9+
"ext-zip": ">=0.0.1"
10+
},
11+
"autoload": {
12+
"psr-4": {
13+
"HttpServer\\": "./"
1914
}
15+
},
16+
"minimum-stability": "stable",
17+
"scripts": {
18+
"deploy": "\\Tars\\deploy\\Deploy::run"
19+
},
20+
"repositories": {
21+
"packagist": {
22+
"type": "composer",
23+
"url": "https://mirrors.aliyun.com/composer/"
24+
}
25+
}
2026
}

examples/tars-http-server/src/conf/ENVConf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function getLogPath() {
3636

3737
$tarsServerConfig = $tarsConfig['tars']['application']['server'];
3838

39-
$logPath = $tarsServerConfig['logpath'];
39+
$logPath = $tarsServerConfig['logpath'] . DIRECTORY_SEPARATOR . $tarsServerConfig['app'] . DIRECTORY_SEPARATOR . $tarsServerConfig['server'] . DIRECTORY_SEPARATOR;
4040

4141
return $logPath;
4242
}

examples/tars-http-server/src/controller/IndexController.php

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@
2424

2525
class IndexController extends Controller
2626
{
27-
// curl "172.16.0.161:28887/Index/index" -i
27+
// curl "node_ip:port/Index/index" -i
2828
public function actionIndex()
2929
{
3030
$this->cookie('key', 1, 10000000, '/', 'www.github.com');
3131
$this->sendRaw('success');
3232
}
3333

34-
// curl "172.16.0.161:28887/Index/testHeader" -i
34+
// curl "node_ip:port/Index/testHeader" -i
3535
public function actionTestHeader()
3636
{
3737
$this->header('test', 1111);
3838
}
3939

40-
// curl "172.16.0.161:28887/Index/testStatus" -i
40+
// curl "node_ip:port/Index/testStatus" -i
4141
public function actionTestStatus()
4242
{
4343
$this->status(401);
4444
}
4545

4646
// Get请求
47-
// curl "172.16.0.161:28887/Index/get?param=1111&c=d&d=e&e=f" -i
47+
// curl "node_ip:port/Index/get?param=1111&c=d&d=e&e=f" -i
4848
public function actionGet()
4949
{
5050
$param = $this->request->data['get']['param'];
@@ -53,28 +53,28 @@ public function actionGet()
5353
}
5454

5555
// Post请求
56-
// curl -d "user=admin&passwd=12345678" "172.16.0.161:28887/Index/post" -i
56+
// curl -d "user=admin&passwd=12345678" "node_ip:port/Index/post1" -i
5757
public function actionPost1()
5858
{
5959
// 对于content-type为application/x-www-form-urlencoded 的form data
60-
$admin = $this->request->data['post']['admin'];
60+
$admin = $this->request->data['post']['user'];
6161

6262
$this->sendRaw('success:'.$admin);
6363
}
6464

6565
// Post请求
66-
//curl -H "Content-Type:application/json" -X POST -d '{"user": "admin", "passwd":"12345678"}' "172.16.0.161:28887/Index/post" -i
66+
//curl -H "Content-Type:application/json" -X POST -d '{"user": "admin", "passwd":"12345678"}' "node_ip:port/Index/post2" -i
6767
public function actionPost2()
6868
{
6969
// 对于对于content-type为application/json
7070
$json = $this->request->data['post'];
71-
$admin = json_decode($json, true)['admin'];
71+
$admin = json_decode($json, true)['user'];
7272

7373
$this->sendRaw('success:'.$admin);
7474
}
7575

7676
// Get请求
77-
// curl -F "[email protected]" -F "phone=123456789" "172.16.0.161:28887/Index/file" -i
77+
// curl -F "[email protected]" -F "phone=123456789" "node_ip:port/Index/file" -i
7878
public function actionFile()
7979
{
8080
$fileName = $this->request->data['files']['image']['name'];
@@ -85,21 +85,7 @@ public function actionFile()
8585
$this->sendRaw('success:'.var_export($this->request->data['files']['image'], true));
8686
}
8787

88-
// curl "172.16.0.161:28887/Index/testSelf?a=b" -i
89-
public function actionTestSelf()
90-
{
91-
$config = new CommunicatorConfig();
92-
$config->setLocator(ENVConf::getLocator());
93-
$config->setModuleName('PHPTest.PHPHttpServer');
94-
$config->setSocketMode(3);
95-
96-
$servant = new TestTafServiceServant($config);
97-
$result = $servant->testSelf();
98-
99-
$this->sendRaw('result:'.$result);
100-
}
101-
102-
// curl "172.16.0.161:28887/Index/TestProperty?a=b" -i
88+
// curl "node_ip:port/Index/TestProperty?a=b" -i
10389
public function actionTestProperty()
10490
{
10591
$config = new CommunicatorConfig();
@@ -113,7 +99,7 @@ public function actionTestProperty()
11399
$this->sendRaw('result:'.$result);
114100
}
115101

116-
// curl "172.16.0.161:28887/Index/TestLotofTags?a=b" -i
102+
// curl "node_ip:port/Index/TestLotofTags?a=b" -i
117103
public function actionTestLotofTags()
118104
{
119105
$config = new CommunicatorConfig();
@@ -131,7 +117,7 @@ public function actionTestLotofTags()
131117
$this->sendRaw(json_encode($outTags, JSON_UNESCAPED_UNICODE));
132118
}
133119

134-
// curl "172.16.0.161:28887/Index/TestBasic?a=b" -i
120+
// curl "node_ip:port/Index/TestBasic?a=b" -i
135121
public function actionTestBasic()
136122
{
137123
$config = new CommunicatorConfig();
@@ -145,7 +131,7 @@ public function actionTestBasic()
145131
$this->sendRaw(json_encode([$d, $e, $f, $ret], JSON_UNESCAPED_UNICODE));
146132
}
147133

148-
// curl "172.16.0.161:28887/Index/TestStruct?a=b" -i
134+
// curl "node_ip:port/Index/TestStruct?a=b" -i
149135
public function actionTestStruct()
150136
{
151137
$config = new CommunicatorConfig();
@@ -165,7 +151,7 @@ public function actionTestStruct()
165151
$this->sendRaw(json_encode([$d, $str], JSON_UNESCAPED_UNICODE));
166152
}
167153

168-
// curl "172.16.0.161:28887/Index/TestMap?a=b" -i
154+
// curl "node_ip:port/Index/TestMap?a=b" -i
169155
public function actionTestMap()
170156
{
171157
$config = new CommunicatorConfig();
@@ -185,10 +171,10 @@ public function actionTestMap()
185171
$d = new OutStruct();
186172
$result = $servant->testMap(88, $b, $m1, $d, $m2);
187173

188-
$this->sendRaw('result:'.$result);
174+
$this->sendRaw('result:'.$result . ' : ' .json_encode(compact('d', 'm2')));
189175
}
190176

191-
// curl "172.16.0.161:28887/Index/TestVector?a=b" -i
177+
// curl "node_ip:port/Index/TestVector?a=b" -i
192178
public function actionTestVector()
193179
{
194180
$config = new CommunicatorConfig();
@@ -208,7 +194,7 @@ public function actionTestVector()
208194
$this->sendRaw(json_encode([$v3, $v4], JSON_UNESCAPED_UNICODE));
209195
}
210196

211-
// curl "172.16.0.161:28887/Index/TestReturn?a=b" -i
197+
// curl "node_ip:port/Index/TestReturn?a=b" -i
212198
public function actionTestReturn()
213199
{
214200
$config = new CommunicatorConfig();
@@ -222,7 +208,7 @@ public function actionTestReturn()
222208
$this->sendRaw(json_encode($simpleStruct, JSON_UNESCAPED_UNICODE));
223209
}
224210

225-
// curl "172.16.0.161:28887/Index/TestReturn2?a=b" -i
211+
// curl "node_ip:port/Index/TestReturn2?a=b" -i
226212
public function actionTestReturn2()
227213
{
228214
$config = new CommunicatorConfig();
@@ -236,7 +222,7 @@ public function actionTestReturn2()
236222
$this->sendRaw(json_encode($map, JSON_UNESCAPED_UNICODE));
237223
}
238224

239-
// curl "172.16.0.161:28887/Index/TestComplicatedStruct?a=b" -i
225+
// curl "node_ip:port/Index/TestComplicatedStruct?a=b" -i
240226
public function actionTestComplicatedStruct()
241227
{
242228
$config = new CommunicatorConfig();
@@ -258,10 +244,10 @@ public function actionTestComplicatedStruct()
258244

259245
$result = $servant->testComplicatedStruct($cs, $vcs, $ocs, $ovcs);
260246

261-
$this->sendRaw('result:'.$result);
247+
$this->sendRaw('result:'.json_encode(compact('result', 'ocs', 'ovcs')));
262248
}
263249

264-
// curl "172.16.0.161:28887/Index/TestComplicatedMap?a=b" -i
250+
// curl "node_ip:port/Index/TestComplicatedMap?a=b" -i
265251
public function actionTestComplicatedMap()
266252
{
267253
$config = new CommunicatorConfig();
@@ -284,7 +270,7 @@ public function actionTestComplicatedMap()
284270
$this->sendRaw(json_encode($omcs, JSON_UNESCAPED_UNICODE));
285271
}
286272

287-
// curl "172.16.0.161:28887/Index/TestEmpty?a=b" -i
273+
// curl "node_ip:port/Index/TestEmpty?a=b" -i
288274
public function actionTestEmpty()
289275
{
290276
$config = new CommunicatorConfig();
@@ -300,14 +286,14 @@ public function actionTestEmpty()
300286
$this->sendRaw(json_encode([$ret], JSON_UNESCAPED_UNICODE));
301287
}
302288

303-
// curl "172.16.0.161:28887/Index/TestConf?a=b" -i
289+
// curl "node_ip:port/Index/TestConf?a=b" -i
304290
public function actionTestConf()
305291
{
306292
$tarsConf = ENVConf::getTarsConf();
307293
$this->sendRaw(json_encode($tarsConf, JSON_UNESCAPED_UNICODE));
308294
}
309295

310-
// curl "172.16.0.161:28887/Index/TestRemoteLog?a=b" -i
296+
// curl "node_ip:port/Index/TestRemoteLog?a=b" -i
311297
public function actionTestRemoteLog()
312298
{
313299
$config = new \Tars\client\CommunicatorConfig();
@@ -316,12 +302,12 @@ public function actionTestRemoteLog()
316302
$config->setCharsetName('UTF-8');
317303

318304
$logServant = new \Tars\log\LogServant($config);
319-
$result = $logServant->logger('PHPTest', 'PHPHttpServer', 'ted.log', '%Y%m%d', ['hahahahaha']);
305+
$logServant->logger('PHPTest', 'PHPHttpServer', 'ted.log', '%Y%m%d', ['hahahahaha']);
320306

321-
$this->sendRaw(json_encode($result, JSON_UNESCAPED_UNICODE));
307+
$this->sendRaw('wrote hahahahaha to ted.log');
322308
}
323309

324-
// curl "172.16.0.161:28887/Index/TestMonolog?a=b" -i
310+
// curl "node_ip:port/Index/TestMonolog?a=b" -i
325311
public function actionTestMonolog()
326312
{
327313
$config = new \Tars\client\CommunicatorConfig();

0 commit comments

Comments
 (0)