micjohnson/weed-php-bundle
Composer 安装命令:
composer require micjohnson/weed-php-bundle
包简介
Weed-FS integration for your Symfony 2 application using WeedPhp
README 文档
README
Weed-FS integration for your Symfony 2 application using WeedPhp
About Weed-FS
Weed-FS Homepage: weedfs
Weed-FS is a simple and highly scalable distributed file system. There are two objectives:
- to store billions of files!
- 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".
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!
Weed-FS models after Facebook's Haystack design paper.
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.
Testing
TODO
Status
Ready for testing / in development
Documentation
This bundle is meant to be tested only, it will be updated rapidly.
This guide assumes:
- You have Weed-FS 0.26+ master/volume(s) running (link above)
- You are using Doctrine
Step 1: Install using composer
Add to your composer.json
"require": {
"micjohnson/weed-php-bundle": "dev-master"
}
Install through composer.phar
php composer.phar update micjohnson/weed-php-bundle
Step 2: Add to AppKernel.php
Enable the bundle in the kernel
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.
// 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
<?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
<?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.
$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.
$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.
You can pass a second param:
$thumbSmallRaw = $weedManager->retrieve($image, "sm");
Read more below.
Step 6: Use WeedManager to store
Use the weedphp's manager to store
$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
$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.
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.
Assuming you have data stored labeled "sm"
$smallThumbRaw = $weedManager->retrieve($image, "sm");
micjohnson/weed-php-bundle 适用场景与选型建议
micjohnson/weed-php-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 1, 最近一次更新时间为 2012 年 12 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「client」 「image storage」 「weedfs」 「clob」 「blob」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 micjohnson/weed-php-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 micjohnson/weed-php-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 micjohnson/weed-php-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Mock PSR-18 HTTP client
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache
- 更新时间: 2012-12-31