2017 © Pedro Peláez
 

symfony-bundle weed-php-bundle

Weed-FS integration for your Symfony 2 application using WeedPhp

image

micjohnson/weed-php-bundle

Weed-FS integration for your Symfony 2 application using WeedPhp

  • Saturday, January 12, 2013
  • by micjohnson
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

weed-php-bundle

Weed-FS integration for your Symfony 2 application using WeedPhp, (*1)

About Weed-FS

Weed-FS Homepage: weedfs, (*2)

Weed-FS is a simple and highly scalable distributed file system. There are two objectives:, (*3)

  1. to store billions of files!
  2. to serve the files fast!

Instead of supporting full POSIX file system semantics, Weed-FS choose to implement only a key~file mapping. Similar to the word "NoSQL", you can call it as "NoFS"., (*4)

Instead of managing all file metadata in a central master, Weed-FS choose to manages file volumes in the central master, and let volume servers manage files and the metadata. This relieves concurrency pressure from the central master and spreads file metadata into volume servers' memories, allowing faster file access with just one disk read operation!, (*5)

Weed-FS models after Facebook's Haystack design paper., (*6)

Weed-FS costs only 40 bytes disk storage for each file's metadata. It is so simple with O(1) disk read that you are welcome to challenge the performance with your actual use cases., (*7)

Testing

TODO, (*8)

Status

Ready for testing / in development, (*9)

Documentation

This bundle is meant to be tested only, it will be updated rapidly., (*10)

This guide assumes: - You have Weed-FS 0.26+ master/volume(s) running (link above) - You are using Doctrine, (*11)

Step 1: Install using composer

Add to your composer.json, (*12)

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

Install through composer.phar, (*13)

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

Step 2: Add to AppKernel.php

Enable the bundle in the kernel, (*14)

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

Step 3: Configure the address and port of your master weed-fs server

Note: This defaults to localhost:9333, you only need to override it if its not default., (*15)

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

Step 4: Extend the base Image Entity

If you are doing images, you might want a single table for all files, (*16)

<?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;
}

Heres the entity you would use, (*17)

<?php
namespace Test\WeedPhpBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Test\WeedPhpBundle\Entity\BaseImage;

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

}

Step 5: Set your entities data property with your files raw data

Data is not persisted, and is only temporary. So be sure to store right after setting the data property., (*18)

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

You can also pass an array, with keys representing the name of the version of the file, and the value being the raw data., (*19)

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

You can access each version of the file seperately using the manager later, keep in mind the default will always be the first you put., (*20)

You can pass a second param:, (*21)

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

Read more below., (*22)

Step 6: Use WeedManager to store

Use the weedphp's manager to store, (*23)

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

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

Step 7: Retrieve and delete files

The manager also retrieves and deletes, (*24)

$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();

By default when you call $weedManager->retrieve($image); it grabs the first, or only version of file, if $data is an array., (*25)

You can optionally pass a second parameter which is the name you gave the version of your file. This will access that version instead of the default., (*26)

Assuming you have data stored labeled "sm", (*27)

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

The Versions

12/01 2013

dev-master

9999999-dev https://github.com/micjohnson/weed-php-bundle

Weed-FS integration for your Symfony 2 application using WeedPhp

  Sources   Download

Apache 2.0

The Requires

 

The Development Requires

client blob image storage weedfs clob