• This repository has been archived on 03/Jun/2019
  • Stars
    star
    267
  • Rank 153,621 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 12 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Object-Oriented API for PHP streams

Streamer

Streamer is an Object-Oriented API for PHP streams.

Why should I use Streams?

A stream is a flow of bytes from one container to the other. You already use streams a lot in PHP, for instance each time you load a file into memory (file_get_contents()). You should explicitly use streams each time that:

  • You need to access data from a container, but you don't know the size of this container (e.g. reading from STDIN, or a web service using streaming)
  • You need to start processing data from a container before the whole transfer is finished (e.g. start zipping a file before it's all in memory)
  • You need to save time and memory

What is Streamer?

PHP has a very elaborate stream API ; unfortunately, it uses functions for most stream operations (except for wrappers - go figure). Streamer is a generic library focusing on offering an object-oriented API to streams, and only that.

Installation

Streamer is published on packagist.org, so you can add it to your composer.json file for an easy installation:

composer require fzaninotto/Streamer

or

{
    "require": {
        "fzaninotto/Streamer": "0.0.1"
    }
}

Example

<?php
use Streamer\Stream,
	Streamer\FileStream,
	Streamer\NetworkStream;

// basic usage
$stream = new Stream(fopen('smiley.png', 'r'));
$image = '';
while (!$stream->isEOF()) {
  $image .= $stream->read();
}

// pipe dreams!
$stream1 = new Stream(fopen('smiley.png', 'r'));
$stream2 = new Stream(fopen('tmp.png', 'w'));
// copy the contents from the first stream to the second one
$stream1->pipe($stream2);

// factory
$fileStream = FileStream::create('smiley.png', 'r');
print_r($fileStream);

$networkStream = NetworkStream::create('tcp://www.google.com:80');
print_r($networkStream);

Credits

Streamer is heavily inspired by other Stream class implementations:

More Repositories

1

Faker

Faker is a PHP library that generates fake data for you
PHP
26,795
star
2

uptime

A remote monitoring application using Node.js, MongoDB, and Twitter Bootstrap.
JavaScript
3,622
star
3

screenshot-as-a-service

Website screenshot service powered by node.js and phantomjs
JavaScript
1,100
star
4

CodeFlower

Source code visualization utility written in JavaScript with d3.js. Does your code look beautiful?
JavaScript
692
star
5

DependencyWheel

A package dependency visualization using d3.js. Currently supports Composer for PHP.
HTML
263
star
6

mongoose-lifecycle

Plugin for Mongoose (Node.js ODM for MongoDB) adding lifecyle events on the model class
JavaScript
94
star
7

Doctrine2ActiveRecord

Experimental ActiveRecord layer on top of Doctrine2 using the Twig templating engine
PHP
85
star
8

cron-as-a-service

Remote cron service built using Node.js and MongoDB
JavaScript
74
star
9

CompanyNameGenerator

Generate names for English tech companies with class
PHP
68
star
10

Head-Up

21
star
11

PHPClassNameGenerator

Generate PSR-0 compliant class names with ease.
PHP
15
star
12

fzaninotto.github.com

Source for Franรงois Zaninotto's blog - Jekyll style
HTML
8
star
13

propel-theme

This is the Trac theme of the www.propelorm.org website
Python
3
star
14

sfCookieSessionStoragePlugin

Cookie-based session storage plugin for the symfony framework
PHP
3
star
15

Lecture-on-Web-Applications-Security

PHP
3
star
16

forumphp

Code for my forum PHP 2010 slides
PHP
2
star
17

parisjs

JavaScript
1
star
18

ra-linked-inputs-tutorial

A sample react-admin app demonstrating the FormDataConsumer component. Support for a video tutorial on YouTube.
HTML
1
star
19

ra-lifecycle-callbacks-tutorial

A sample react-admin app demonstrating lifecycle callbacks. Support for a video tutorial on YouTube.
TypeScript
1
star
20

ra-admin-tutorial

A sample react-admin app demonstrating the Admin component. Support for a video tutorial on YouTube.
TypeScript
1
star