micjohnson/weed-php-bundle

使用 WeedPhp 为您的 Symfony 2 应用程序集成 Weed-FS

安装: 27

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 1

公开问题: 0

类型:symfony-bundle

dev-master 2013-01-12 01:41 UTC

This package is not auto-updated.

Last update: 2024-09-28 13:30:20 UTC


README

Weed-FS 集成,用于您的 Symfony 2 应用程序,使用 WeedPhp

关于 Weed-FS

Weed-FS 主页: weedfs

Weed-FS 是一个简单且高度可扩展的分布式文件系统。有两个目标:

  1. 存储数十亿个文件!
  2. 快速提供文件!

与支持完整的 POSIX 文件系统语义不同,Weed-FS 选择仅实现键~文件映射。类似于“NoSQL”这个术语,你可以称之为“NoFS”。

与在中央主节点中管理所有文件元数据不同,Weed-FS 选择在中央主节点中管理文件卷,并让卷服务器管理文件和元数据。这减轻了中央主节点的并发压力,并将文件元数据分散到卷服务器的内存中,只需一次磁盘读取操作即可实现更快的文件访问!

Weed-FS 模仿了 Facebook 的 Haystack 设计论文。

Weed-FS 每个文件元数据的磁盘存储只需 40 字节。由于具有 O(1) 的磁盘读取,你可以挑战你的实际使用案例的性能。

测试

待办事项

状态

准备测试/开发中

文档

此包仅供测试,它将迅速更新。

本指南假设

  • 您正在运行 Weed-FS 0.26+ 主节点/卷(链接在上文)
  • 您正在使用 Doctrine

步骤 1:使用 composer 安装

将其添加到 composer.json 中

"require": {
    "micjohnson/weed-php-bundle": "dev-master"
}

通过 composer.phar 安装

php composer.phar update micjohnson/weed-php-bundle

步骤 2:将其添加到 AppKernel.php 中

在内核中启用此包

    public function registerBundles()
    {
        $bundles = array(
            // ...
			new Micjohnson\WeedPhpBundle\MicjohnsonWeedPhpBundle(),
        );
    }

步骤 3:配置主 Weed-FS 服务器地址和端口

注意:此默认值为 localhost:9333,除非默认值,否则您不需要覆盖它。

// app/config/parameters.yml
parameters:
    weed_php.master.address: "localhost:9333"

步骤 4:扩展基本 Image Entity

如果您正在处理图像,您可能希望为所有文件使用单个表

<?php
namespace Test\WeedPhpBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Micjohnson\WeedPhpBundle\Entity\WeedStorableFile;

/**
 * @ORM\Entity()
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({"baseimage" = "Test\WeedPhpBundle\Entity\BaseImage", "webimage" = "Test\WeedPhpBundle\Entity\WebImage"})
 * @ORM\Table(name="test_weed_php")
 *
 */
class BaseImage extends WeedStorableFile
{
    /**
     *
     * id
     * @var unknown_type
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
}

以下是您将使用的实体

<?php
namespace Test\WeedPhpBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Test\WeedPhpBundle\Entity\BaseImage;

/**
 * @ORM\Entity()
 */
class WebImage extends BaseImage
{
    
}

步骤 5:使用文件原始数据设置实体数据属性

数据不会持久化,并且仅是临时的。因此,在设置数据属性后,请务必存储。

$image = new WebImage();
$image->setData($rawImage);

您也可以传递一个数组,键表示文件的版本名称,值是原始数据。

$image = new WebImage();
$imageVersions = array("full"=>$fullImageRaw, "sm"=>$smallThumbRaw, "lg"=>$largeThumbRaw);
$image->setData($imageVersions);

您可以使用管理器单独访问文件的每个版本,请注意,默认值始终是您首先放置的。

您还可以传递第二个参数

$thumbSmallRaw = $weedManager->retrieve($image, "sm");

下面了解更多信息。

步骤 6:使用 WeedManager 存储

使用 weedphp 的管理器进行存储

$weedManager = $this->get('weed_php.manager');
$weedManager->store($image);

//persist to save location data in database
$entityManager->persist($image);
$entityManager->flush();

步骤 7:检索和删除文件

管理器还提供检索和删除功能

$weedManager = $this->get('weed_php.manager');

$imageRawData = $weedManager->retrieve($image);

$weedManager->delete($image);

// file is gone, you can get rid fo the entity
$entityManager->remove($image);
$entityManager->flush();

默认情况下,当您调用 $weedManager->retrieve($image); 时,如果 $data 是一个数组,它会获取第一个或唯一的版本。

您可以选择传递第二个参数,这是您为文件版本指定的名称。这将访问该版本而不是默认版本。

假设您存储了标记为 "sm" 的数据

$smallThumbRaw = $weedManager->retrieve($image, "sm");