Skip to content

Instantly share code, notes, and snippets.

@sasezaki
sasezaki / Index.php
Last active October 4, 2015 16:03
fix REAL PSR-7 READY
<?php
namespace BEAR\Project\Resource\Page;
use BEAR\Resource\ResourceObject;
class Index extends ResourceObject
{
@sasezaki
sasezaki / stream_banashi.md
Last active August 29, 2015 14:22
ストリーム 関連のプロジェクトの話

#ストリーム 関連のプロジェクト

ここ最近psr-7を受けて、streamまわりのコンポーネントを作ったりしてたのでその整理

自分が手を加えたもの

SfpIteratorUrl

https://github.com/struggle-for-php/SfpIteratorUrl

  • Iterator to stream に出力するのが目的
<?php
class CallbackFilter extends php_user_filter
{
public function filter($in, $out, &$consumed, $closing) {
$gen = $this->params['generator'];
@sasezaki
sasezaki / **memory_usage
Last active August 29, 2015 14:22
memory usage echo vs stream_copy_to_stream when 10M send
$ curl "http://localhost/tmp/diactoros/test.php?bigsize" > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 10.0M 100 10.0M 0 0 35.9M 0 --:--:-- --:--:-- --:--:-- 35.9M
$ cat memory_get_usage.txt
10900304
$ curl "http://localhost/tmp/diactoros/test.php?emitter=streamcopy&bigsize" > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
<?php
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\EventManager;
use Doctrine\SkeletonMapper\DataRepository\ArrayObjectDataRepository;
use Doctrine\SkeletonMapper\Hydrator\BasicObjectHydrator;
use Doctrine\SkeletonMapper\Mapping\ClassMetadata;
use Doctrine\SkeletonMapper\Mapping\ClassMetadataFactory;
use Doctrine\SkeletonMapper\ObjectFactory;
use Doctrine\SkeletonMapper\ObjectIdentityMap;
@sasezaki
sasezaki / ob_start.php
Last active August 29, 2015 14:15
gently handle memory with ob_start 's callback & StreamableInterface
<?php
// $ php -d memory_limit=6M ob_start.php
class TempStreamable
{
public $fp;
public function __construct()
{
$OneMB = 1 * 1024 * 1024;
@sasezaki
sasezaki / steeem.php
Created December 12, 2014 14:25
seq 100 | php -d short_open_tag=1 streeem.php
<?
while($x = fgets(STDIN)?:die) {
if ($x % 15 == 0):
?>FIZZBUZZ<?
elseif ($x % 3 == 0):
?>FIZZ<?
elseif ($x % 5 == 0):
?>Buzz<?
else: ?>x<?
endif; ?>
@sasezaki
sasezaki / register_file.php
Last active August 29, 2015 14:07
example of stream wrappers
<?php
// a fork of http://php.net/manual/ja/stream.streamwrapper.example-1.php
class VariableStream {
var $position;
var $varname;
function stream_open($path, $mode, $options, &$opened_path)
{
//$url = parse_url($path);
$ php -v
PHP 5.5.14-2+deb.sury.org~precise+1 (cli) (built: Jul 2 2014 12:07:02)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
{
"require": {
"guzzlehttp/guzzle": "4.1.*@dev",
"guzzlehttp/streams": "dev-master"
}
}