首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过PHP优化批量上传到Rackspace云文件

通过PHP优化批量上传到Rackspace云文件
EN

Stack Overflow用户
提问于 2012-07-10 23:50:27
回答 1查看 885关注 0票数 0

我们有一个应用程序,它解析来自外部源的数据并将其本地化,并将图像保存和调整大小作为进程的最后一步。考虑到到目前为止我们处理的200万张图像的大小,我们一直在使用Rackspace文件托管数据.

代码语言:javascript
复制
require('/var/libs/rackspace/cloudfiles.php');
$auth = new CF_Authentication('xxx', 'yyyy');
$auth->authenticate();
$conn = new CF_Connection($auth,true);
$container = $conn->get_container('some container');

foreach ($lotsofitems as $onitem){

    // check the record
    // save the image to disk with cURL
    // resize it into 4 more versions
    // post it to rackspace

    if(file_exists('/var/temp/'. $image_id . '_full'. $image_type)){
        $object = $container->create_object($image_id . '_full' . $image_type);
        $object->load_from_filename('/var/temp/'. $image_id . '_full' . $image_type);
        unlink('/var/temp/'. $image_id . '_full' . $image_type); // remove the temp save
    }

    if(file_exists('/var/temp/'. $image_id . '_big'. $image_type)){
        $object = $container->create_object($image_id . '_big' . $image_type);
        $object->load_from_filename('/var/temp/'. $image_id . '_big' . $image_type);
        unlink('/var/temp/'. $image_id . '_big' . $image_type); // remove the temp save
    }

    if(file_exists('/var/temp/'. $image_id . '_med'. $image_type)){
        $object = $container->create_object($image_id . '_med' . $image_type);
        $object->load_from_filename('/var/temp/'. $image_id . '_med' . $image_type);
        unlink('/var/temp/'. $image_id . '_med' . $image_type); // remove the temp save
    }

    // delete the original
    // repeat

}

在优化解析器、GD等之后,我们已经对处理过程进行了基准测试,图像处理大约需要1秒,但是将5个图像变体传输到Rackspace需要花费2-5秒的时间,有时甚至会达到10+。

  • 获取图像: 1341964436
  • got图像: 1341964436
  • 调整大小图像: 1341964437
  • 云图: 1341964446
  • 云图: 1341964448
  • 完成图像: 1341964448

另外几点:

  1. 我们的处理服务器也在Rackspace的云上。
  2. 共有5种图像版本,从30 2kb到2kb不等。
  3. 所有图像在传输之前保存到磁盘,然后再删除。
  4. 我们使用的容器总体上使用了几个,但每个项目都启用了CDN。

有没有人对大量传输到Rackspace有建议?在一定的持续时间/请求数量之后,我们是否应该重新连接?以其他方式优化我们的连接?或者仅仅是分叉进程和运行大量调用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-16 20:48:00

你试过使用CloudFuse吗?它允许您将Rackspace CloudFiles桶挂载为挂载。

我用过这个,而且很不错--是他们为Rackspace设计的。

http://sandeepsidhu.wordpress.com/2011/03/07/mounting-cloud-files-using-cloudfuse-into-ubuntu-10-10-v2/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11423658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档