我们正在尝试使用PHP库(https://github.com/softlayer/softlayer-object-storage-php)将文件上传到对象存储中,并获得408 Request Timeout错误。
请求超时
服务器等待客户端发送请求的时间太长。
当我们上传大小约为1MB的文件时会发生这种情况。
require_once('libs/softlayer/ObjectStorage/Util.php');
$tokenStore = ObjectStorage_TokenStore::factory('file', array('ttl' => 3600, 'path' => '/tmp'));
ObjectStorage::setTokenStore($tokenStore);
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);
$host = 'https://sng01.objectstorage.softlayer.net/auth/v1.0/';
$username = 'xxxxxx';
$password = 'xxxxxx';
$objectStorage = new ObjectStorage($host, $username, $password, $options);
$container = 'xxxx/';
$files = ['/tmp/objectstorage_test/sample_617K.zip', '/tmp/objectstorage_test/sample_1_3M.zip'];
foreach($files as $file){
print_r("Uploading $file ...");
try{
$filename = basename($file);
$url = $container . $filename;
$content_type = 'application/octet-stream';
$rst = $objectStorage->with($this->container.$url)
->setLocalFile($file)
->setHeader('Content-type', $content_type)
->create();
print_r($rst);
print_r("Successfully uploading $file");
}catch(Exception $e){
print_r($e->getMessage());
}
}
我尝试上传了2个文件,并成功上传了第一个文件(sample_617K.zip)。第二个文件(sample_1_3M.zip)在5分钟后返回错误408请求超时。
顺便说一下,几个月前工作正常。 请进一步咨询。
答案 0 :(得分:1)
在一些调试/测试之后,我使用CURL作为适配器设置而不是SOCKET,它得到修复。 :)
答案 1 :(得分:0)
我成功上传大于1 MB的文件。 我使用您的脚本上传了两个文件(4.22 MB和4.66 MB),它运行正常。你身边有什么奇怪的东西,你是否尝试增加超时?