* @license PHP License * @package test * @subpackage rest */ /** * load factory */ error_reporting( E_ALL | E_STRICT ); ini_set( 'display_errors', 1 ); ini_set('max_execution_time', 0); require_once '../../../wbLoader.php'; WBClass::load('WBClock'); $config = WBClass::create( 'WBConfig' ); $config->load( 'config' ); $serverPort = 80; $serverProtocol = 'http'; $serverHost = $config->get('page/server'); $serverPath = $config->get('page/docroot') . $config->get('page/service/rest'); // form default parameter $req = array( 'serverProtocol'=> $serverProtocol, 'serverHost' => $serverHost, 'serverPath' => $serverPath, 'serverPort' => $serverPort, 'chunkSize' => '200000', 'file' => '', 'nickname' => 'gerd', 'password' => 'gerd123', 'method' => 'GET', 'path' => '/', 'cookies' => 'REST-Client-Message=How cool is that?', 'headers' => << $v) { $req[$k] = stripslashes($v); } } } $req['chunkSize'] = intval($req['chunkSize']); $xml = << %s EOT; // files $files = array(); $dir = dirname(__FILE__). '/../../unit/vfs/import'; foreach (new DirectoryIterator($dir) as $f) { if ($f->isDot() || $f->isDir()) { continue; } $files[] = array( 'value' => $f->getFilename(), 'desc' => $f->getFilename() . ' (' . $f->getSize() . ')' ); } // start client include_once dirname(__FILE__) . '/RestClient.php'; $client = new RestClient($req['serverHost'], $req['serverPort']); $req['headers'] = 'Authorization: Basic ' . base64_encode($req['nickname'] . ':' . $req['password']) . "\n" . $req['headers']; $auth = setHeaders($client, $req['headers']); setCookies($client, $req['cookies']); /* $state = $client->getResponseState(); $header = $client->getResponseHeader(); $body = $client->getResponseBody(); $reqHeader = $client->getRequestHeader(); $cookies = $client->getCookies(); */ echo '' . "\n"; ?>

REST Client

Server:
protocol://server:port
://:
Path:

Auth data:
Nickname
Password

Cookies:

Header:

Upload:
Chunk Size
File


no file EOT; } ?> Init:
$size
$md5
EOT;

$tInit  =   WBClock::now();

$body   =   sprintf($xml, $cnt);
$client->put($req['serverPath'] . '/explorer/upload', $body);
echo htmlspecialchars($body);
$res    =   $client->getResponseBody();
echo htmlspecialchars($res);

$uid        =   null;
if (preg_match('|(\d+)|i', $res, $match)) {
    $uid    =   $match[1];
}

// $client->delete($req['serverPath'] . '/explorer/upload/');

?>
Chunks:
= $req['chunkSize']) {
        $tChunk =   WBClock::now();
        $chunk  =   base64_encode($chunk);
        $cnt    =   <<$pos
$chunk
EOT;
        $chunk  =   '';
        $pos    =   ftell($fh);

        $body   =   sprintf($xml, $cnt);
        // echo htmlspecialchars($body) . "\n";
        echo "upload body size " . strlen($body) . " bytes ";

        if ($uid) {
            $client->post($req['serverPath'] . '/explorer/upload/' . $uid, $body);
            $res    =   $client->getResponseBody();
            // echo htmlspecialchars($res);
        }
        
        echo WBClock::stop($tChunk, 1000, 0 ) . "ms\n";
        flush();
    }
}
fclose($fh);
echo 'upload time: ' . WBClock::stop($tInit, 1000, 0) . "ms\n";

?>
File:
{$req['file']}
0
EOT;

$body   =   sprintf($xml, $cnt);
$client->put($req['serverPath'] . '/explorer/file/' . $uid, $body);

echo 'file creation time: ' . WBClock::stop($tNow, 1000, 0) . "ms\n";


echo htmlspecialchars($body);
$res    =   $client->getResponseBody();
echo htmlspecialchars($res);

?>