forked from qpwoeiru96/PHP-FastDFS-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracker.php
More file actions
71 lines (49 loc) · 1.75 KB
/
Tracker.php
File metadata and controls
71 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* PHP-FastDFS-Client (FOR FastDFS v4.0.6)
*
* 用PHP Socket实现的FastDFS客户端
*
* @author: $Author: QPWOEIRU96
* @version: $Rev: 521 $
* @date: $Date: 2014-01-17 09:54:45 +0800 (周五, 17 一月 2014) $
*/
namespace FastDFS;
class Tracker extends Base{
/**
* 根据GroupName申请Storage地址
*
* @command 104
* @param string $group_name 组名称
* @return array/boolean
*/
public function applyStorage($group_name) {
$req_header = self::buildHeader(104, Base::GROUP_NAME_MAX_LEN);
$req_body = self::padding($group_name, Base::GROUP_NAME_MAX_LEN);
$this->send($req_header . $req_body);
$res_header = $this->read(Base::HEADER_LENGTH);
$res_info = self::parseHeader($res_header);
if($res_info['status'] !== 0) {
throw new FastDFSException(
'something wrong with get storage by group name',
$res_info['status']);
return FALSE;
}
$res_body = !!$res_info['length']
? $this->read($res_info['length'])
: '';
$group_name = trim(substr($res_body, 0, Base::GROUP_NAME_MAX_LEN));
$storage_addr = trim(substr($res_body, Base::GROUP_NAME_MAX_LEN,
Base::IP_ADDRESS_SIZE - 1));
list(,,$storage_port) = unpack('N2', substr($res_body,
Base::GROUP_NAME_MAX_LEN + Base::IP_ADDRESS_SIZE - 1,
Base::PROTO_PKG_LEN_SIZE));
$storage_index = ord(substr($res_body, -1));
return array(
'group_name' => $group_name,
'storage_addr' => $storage_addr,
'storage_port' => $storage_port,
'storage_index' => $storage_index
);
}
}