99designs/facade

A PHP5 library for accessing various services via a stream based request/response pattern

Maintainers

Details

github.com/99designs/facade

Source

Installs: 31 740

Dependents: 0

Suggesters: 0

Stars: 5

Watchers: 49

Forks: 4

1.0.0 2012-06-12 09:26 UTC

README

Facade is an open-source library for memory-effecient consumption of stream-based protocols like HTTP.

Included is a streaming HTTP client and a streaming AWS S3 client. 99designs uses these to stream large designs from AWS to upstream clients without buffering the entire file in memory or on disk at any one time.

Examples

Streaming a file from disk to S3:

<?php

$s3 = new Facade_S3(getenv('AWS_ACCESS_KEY_ID'), getenv('AWS_SECRET_ACCESS_KEY'));
$file = '/uploads/largeimage.jpg';

$response = $s3
	->put("/llamas/largeimage.jpg")
	->setStream(Facade_Stream::fromFile($file))
	->setContentType('image/jpeg')
	->setHeader('Content-MD5: '.base64_encode(md5_file($file, true)))
	->send();

Streaming an S3 file to a client:

<?php

$s3 = new Facade_S3(getenv('AWS_ACCESS_KEY_ID'), getenv('AWS_SECRET_ACCESS_KEY'));

$response = $s3
  ->get('/llamas/largeimage.jpg')
  ->send();

stream_copy_to_stream($response->getStream(), STDOUT);