Exemplo n.º 1
0
<?php

set_time_limit(10);
include __DIR__ . '/Exception.php';
include __DIR__ . '/Base.php';
include __DIR__ . '/Tracker.php';
include __DIR__ . '/Storage.php';
$time_start = microtime(TRUE);
$tracker_addr = '10.21.3.101';
$tracker_port = 806;
$tracker = new FastDFS\Tracker($tracker_addr, $tracker_port);
$storage_info = $tracker->applyStorage('group1');
//var_dump($storage_info);
$group_name = 'group1';
$file_path = 'M00/00/00/ChUDZVX2blCAPsBOAAAKWhzQa64704.png';
//$file_path = 'M00/00/00/CgAABVFYZgmAQ_9nAKnrXobBHdI433.rar';
//$appender_file_path = 'M00/00/00/CgAABVFc8duEOo6HAAAAAD1cKVQ817.txt';
$storage = new FastDFS\Storage($storage_info['storage_addr'], $storage_info['storage_port']);
var_dump($storage->uploadFile($storage_info['storage_index'], dirname(__DIR__) . '/test.png'));
$time_end = microtime(TRUE);
printf("[内存最终使用: %.2fMB]\r\n", memory_get_usage() / 1024 / 1024);
printf("[内存最高使用: %.2fMB]\r\n", memory_get_peak_usage() / 1024 / 1024);
printf("[页面执行时间: %.2f毫秒]\r\n", ($time_end - $time_start) * 1000);
Exemplo n.º 2
0
 protected function moveFile($path, $status = 0)
 {
     if (!extension_loaded('fastdfs_client')) {
         $type = 0;
     } else {
         $type = 1;
     }
     if ($status == 0) {
         if (!$type) {
             $ext = self::getExtByPath(self::trimSpace($path));
             $fileName = md5(uniqid()) . ($ext ? '.' . $ext : '');
             $newDir = DATA_DIR . date('Ymd');
             $newPath = $newDir . DS . $fileName;
             if (!file_exists($newDir)) {
                 mkdir($newDir, 0777, true);
             }
             if (rename($path, $newPath)) {
                 return $newPath;
             } else {
                 return false;
             }
         } else {
             include FDFS . 'Exception.php';
             include FDFS . 'Base.php';
             include FDFS . 'Tracker.php';
             include FDFS . 'Storage.php';
             $confinfo = (include FDFS . 'config.php');
             $group = (include FDFS . 'group.php');
             if ($confinfo['tracker']) {
                 shuffle($confinfo['tracker']);
             }
             $gs = array_keys((array) $group);
             if ($gs) {
                 shuffle($gs);
             }
             $tracker = new FastDFS\Tracker($confinfo['tracker'][0], $confinfo['trackerPort']);
             $storageInfo = $tracker->applyStorage($gs[0]);
             $storage = new FastDFS\Storage($storageInfo['storage_addr'], $storageInfo['storage_port']);
             $ret = $storage->uploadFile($storageInfo['storage_index'], $path);
             unlink($path);
             return $ret['group'] . DS . $ret['path'];
         }
     } else {
         return $path;
     }
 }
Exemplo n.º 3
0
<?php

set_time_limit(10);
include __DIR__ . '/Exception.php';
include __DIR__ . '/Base.php';
include __DIR__ . '/Tracker.php';
include __DIR__ . '/Storage.php';
$time_start = microtime(TRUE);
$tracker_addr = '168.192.122.29';
$tracker_port = 22122;
$tracker = new FastDFS\Tracker($tracker_addr, $tracker_port);
$storage_info = $tracker->applyStorage('lms');
var_dump($storage_info);
$group_name = 'lms';
//$file_path = 'M00/00/00/CgAABVFYZgmAQ_9nAKnrXobBHdI433.rar';
//$appender_file_path = 'M00/00/00/CgAABVFc8duEOo6HAAAAAD1cKVQ817.txt';
$storage = new FastDFS\Storage($storage_info['storage_addr'], $storage_info['storage_port']);
var_dump($storage->downloadToFile('lms', 'M00/00/00/qMB6HVLYiECAJ2KTACvD-UdfQeU480.pdf', __DIR__ . '/test.pdf'));
$time_end = microtime(TRUE);
printf("[内存最终使用: %.2fMB]\r\n", memory_get_usage() / 1024 / 1024);
printf("[内存最高使用: %.2fMB]\r\n", memory_get_peak_usage() / 1024 / 1024);
printf("[页面执行时间: %.2f毫秒]\r\n", ($time_end - $time_start) * 1000);