Conditions | 4 |
Paths | 6 |
Total Lines | 22 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 3 | Features | 0 |
1 | <?php |
||
18 | function getUpyunFileSize($path) |
||
19 | { |
||
20 | $url = getFileUrl($path); |
||
21 | $client = new Client([ |
||
22 | 'timeout' => 120, |
||
23 | 'connect_timeout' => 120, |
||
24 | 'http_errors' => false, |
||
25 | ]); |
||
26 | |||
27 | for ($i = 0; $i < 3; $i++) { |
||
28 | try { |
||
29 | $response = $client->head($url); |
||
30 | if ($response->getStatusCode() === 200) { |
||
31 | return (int) $response->getHeaderLine('Content-Length'); |
||
32 | } |
||
33 | } catch (RequestException $e) { |
||
34 | // 忽略网络异常,继续重试 |
||
35 | } |
||
36 | usleep(500000); // 等待 500ms |
||
37 | } |
||
38 | |||
39 | return false; |
||
40 | } |
||
42 |