【问题标题】:408 Request Timeout error while upload into ObjectStorage上传到 ObjectStorage 时出现 408 请求超时错误
【发布时间】:2016-12-02 15:12:47
【问题描述】:

我们正在尝试使用 PHP 库 (https://github.com/softlayer/softlayer-object-storage-php) 将文件上传到对象存储并收到 408 请求超时错误。

请求超时

服务器等待客户端发送请求的时间过长。

当我们上传大小约为 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 Request Timeout。

顺便说一句,几个月前它运行良好。 请多多指教。

【问题讨论】:

    标签: ibm-cloud-infrastructure


    【解决方案1】:

    经过一些调试/测试后,我使用 CURL 代替 SOCKET 进行适配器设置,它得到了修复。 :)

    【讨论】:

    • 我遇到了同样的问题。更改为 CURL 解决了我的问题。
    【解决方案2】:

    我已成功上传大于 1 MB 的文件。 我使用您的脚本上传了两个文件(4.22 MB 和 4.66 MB),它运行良好。你身边有什么奇怪的事情,你有没有尝试增加超时时间?

    【讨论】:

    • 感谢您的回复。我试过增加 Curl 的超时时间,但没有帮助。你指的是哪个超时?请进一步建议我如何更深入地捕捉问题。谢谢
    • 嗨@ruber-cuellar,顺便说一句,您使用的是什么网络服务器以及您的超时设置是什么?请分享,谢谢
    猜你喜欢
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 2015-09-04
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    • 2018-02-01
    相关资源
    最近更新 更多