phpwax/mogilefs

MogileFS Component

dev-master / 1.0.x-dev 2012-11-20 14:22 UTC

This package is auto-updated.

Last update: 2024-10-17 12:27:10 UTC


README

This library is an abstraction model for a file stored in MogileFS. The idea is to have a clearly defined api to use for storing and retrieving files from MogileFS.

On find, only paths are retrieved by default, while other properties like domain and class are lazyloaded on request.

This model also include a mysql adapter, as a hack to do bulk operations for looking up multiple paths in one operation. This adapter is likely to break for future MogileFS versions, but MogileFS currently doesn’t support getting multiple paths in one query natively.

Example usage

<?php
// Config example
$config = array(
	'adapter' => array(
		'tracker' => array('127.0.0.1','127.0.0.2:1234'),
		'domain' => 'dev'
	);
);

// Save
$mapper = new MogileFS_File_Mapper($config); // see tests/config.php
$file = new MogileFS_File();
$file->setKey('motd');
$file->setFile('/etc/motd');
$savedFile = $mapper->save($file);

// Find
$file = $mapper->find('motd');
var_dump($file->getPaths());

Config options

Options should be injected into MogileFS_File_Mapper constructor in an associative array.

For an example see: tests/config.php

Mapper options:

  • adapter

  • defaultadapter

The adapter option can either be an instance of MogileFS_File_Mapper_Adapter_Abstract, or a set of adapter options for the defaultadapter which should contain class name of adapter to instantiate if no adapter is set.

Tracker adapter options:

  • domain (required)

  • tracker (required)

  • request_timeout (seconds)

  • noverify

  • pathcount

The tracker section should contain an array of MogileFS trackers.

Mysql adapter options:

  • domain (required)

  • pdo_options (required)

  • username

  • password

Testing

Tests where performed on Ubuntu 12.04.

To get tests running I installed MogileFS as described in the quickstart: https://code.google.com/p/mogilefs/wiki/QuickStartGuide

I also did one additional command:

	mogadm class add toast dev --mindevcount=3

tests/config.php is set up according to the above setup

Design

All properties except key and paths are lazyloaded on request. This means that no request is sent to the backend server for file info until the getClass() or similar is called within the MogileFS_File model.

MogileFS::getFile() downloads the file to a temporary local file, which should to be deleted by application after use.

Adapters interact with datasource, while mapper populate the File model from adapter output. All adapters have to produce the same output for mapper to parse it correctly.

A test adapter is implemented to allow for application testing without having a live MogileFS running

Naming convention, and design tries to follow that of the Zend Framework 1.x. This also includes sub optimal require_once calls, for compatibility. I reccomend you use an autoloader instead.