SlideShare a Scribd company logo
Globalcode – Open4education
TDC São Paulo 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streams
WHAT IS A
STREAM?
A stream is a body of water
[1]
with a current,
confined within a bed and stream banks.
Depending on its location or certain
characteristics, a stream may be referred to
as a branch, brook, beck, burn, creek, crick,
gill (occasionally ghyll), kill, lick, mill race, rill,
river, syke, bayou, rivulet, streamage, wash,
run, or runnel.
https://en.wikipedia.org/wiki/Stream
TDC São Paulo 2016 - Become a jedi with php streams
?
DATA
FLOW
TDC São Paulo 2016 - Become a jedi with php streams
PHP
F* FILE*
fopen
fpassthru
fputcsv
fputs
fread
fscanf
fseek
fstat
ftell
ftruncate
fwrite
file_​exists
file_​get_​contents
file_​put_​contents
file
fileatime
filectime
filegroup
fileinode
filemtime
fileowner
fileperms
RESOURCE
FILE
CONTENTS
fopen(
‘file.txt’,
‘r+’
);
file_​get_​contents(
‘file.txt’
);
WRAPPERS
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
fopen(
‘file.txt’, ‘r+’
);
fopen(
‘file://file.txt’, ‘r+’
);
!= ?
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
print file_get_contents(
'http://marabesi.
com'
);
TDC São Paulo 2016 - Become a jedi with php streams
$contexto = stream_context_create([
'http' => [
'method' => 'POST'
'header' => 'Content-Type:
application/x-www-form-urlencoded',
'content' => 'livro=php'
]
]);
print file_get_contents(
http://marabesi.com',
false,
$context
);
$fp = fopen(
'http://marabesi.com',
'r',
false,
$context
);
print fgets($fp);
http://php.net/manual/en/context.php
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
$fp = fopen(
'ftp://usuario:senha' .
'@meu_servidor.com' .
'/home/matheusmarabesi/index.php',
'r'
);
TDC São Paulo 2016 - Become a jedi with php streams
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
$put = fopen(
'php://stdin, 'r'
);
print fgets($put);
TDC São Paulo 2016 - Become a jedi with php streams
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
print file_get_contents(
'data://text/plain, Utilizando o
wrapper data://'
);
print file_get_contents(
'data://text/plain, Utilizando o
wrapper data://'
);
<img src="data:
image/jpeg;base64,
YXNodXNhdXNhdWlzYXVzYWl1"
/>
print file_get_contents( 'data:
//text/plain;base64,
VXRpbGl6YW5kbyBzdHJlYW1zIGVtIFBIUCAh');
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
TDC São Paulo 2016 - Become a jedi with php streams
$diretorio = new
RecursiveDirectoryIterator(
'/var/www'
);
1
$iterator = new
RecursiveIteratorIterator(
$diretorio
);
2
$arquivos = new RegexIterator(
$iterator, '/^.+.php/',
RecursiveRegexIterator::GET_MATCH
);
3
$diretorio = new RecursiveDirectoryIterator('/var/www');
$iterator = new RecursiveIteratorIterator($diretorio);
$arquivos = new RegexIterator(
$iterator, '/^.+.php/', RecursiveRegexIterator::GET_MATCH
);
foreach ($diretorio as $arquivos) {
print $arquivos->getFilename();
}
TDC São Paulo 2016 - Become a jedi with php streams
$diretorio = new
RecursiveDirectoryIterator(
'glob://var/www/*.php'
);
foreach ($diretorio as $arquivos) {
print $arquivos->getFilename();
}
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
TDC São Paulo 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streams
ogg://
file://
http://
ftp://
php://
data://
glob://
ogg://
mandinga://
streamWrapper {
public resource $context ;
__construct ( void )
__destruct ( void )
public bool dir_closedir ( void )
public bool dir_opendir ( string $path , int $options )
public string dir_readdir ( void )
public bool dir_rewinddir ( void )
public bool mkdir ( string $path , int $mode , int $options )
public bool rename ( string $path_from , string $path_to )
public bool rmdir ( string $path , int $options )
public resource stream_cast ( int $cast_as )
public void stream_close ( void )
public bool stream_eof ( void )
public bool stream_flush ( void )
public bool stream_lock ( int $operation )
public bool stream_metadata ( string $path , int $option , mixed $value )
public bool stream_open ( string $path , string $mode , int $options , string &$opened_path
)
public string stream_read ( int $count )
public bool stream_seek ( int $offset , int $whence = SEEK_SET )
public bool stream_set_option ( int $option , int $arg1 , int $arg2 )
public array stream_stat ( void )
THERE IS MORE
class Mandinga {
private $arquivo;
public function stream_open($arquivo, $modo)
{
if (!file_exists($arquivo)) {
throw new Exception(
'O arquivo informado não existe'
);
$this->arquivo = fopen($arquivo, $modo);
return true;
}
}
public function stream_read($bytes)
{
return fread($this->file,
$bytes);
}
public function stream_eof()
{
return feof($this->file);
}
stream_register_wrapper
stream_wrapper_register
!= ?
stream_register_wrapper(
'mandinga', 'Mandinga'
);
stream_register_wrapper(
'mandinga', 'Mandinga'
);
ALIAS
CLASS NAME
print file_get_contents(
mandinga://pessoas.txt'
);
TDC São Paulo 2016 - Become a jedi with php streams

More Related Content

PDF
scdevsumit 2016 - Become a jedi with php streams
PDF
TDC2016SP - Become a jedi with PHP streams
PPTX
Php File Operations
PDF
Php file handling in Hindi
PPTX
Ch3(working with file)
PPTX
Scripting 101
PDF
File system
TXT
Logrotate sh
scdevsumit 2016 - Become a jedi with php streams
TDC2016SP - Become a jedi with PHP streams
Php File Operations
Php file handling in Hindi
Ch3(working with file)
Scripting 101
File system
Logrotate sh

What's hot (19)

DOCX
Php files
RTF
Unix lab manual
PDF
Unix 1st sem lab programs a - VTU Karnataka
KEY
Grails In The Wild
PPT
Filing system in PHP
ODT
Huong dan cai dat hadoop
PDF
리눅스 간단 강의 5강
PPT
php file uploading
PDF
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
XLS
Up.Php
PDF
PPT
spug_2008-08
PDF
Find & Locate utility Linux
PDF
Plone Conference 2008 Lightning Talk Static Zope Rpx
PPTX
Chap 5 php files part-2
PPT
05 File Handling Upload Mysql
PPTX
R- create a table from a list of files.... before webmining
PPT
Assic 16th Lecture
PPT
Synapseindia reviews sharing intro on php
Php files
Unix lab manual
Unix 1st sem lab programs a - VTU Karnataka
Grails In The Wild
Filing system in PHP
Huong dan cai dat hadoop
리눅스 간단 강의 5강
php file uploading
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Up.Php
spug_2008-08
Find & Locate utility Linux
Plone Conference 2008 Lightning Talk Static Zope Rpx
Chap 5 php files part-2
05 File Handling Upload Mysql
R- create a table from a list of files.... before webmining
Assic 16th Lecture
Synapseindia reviews sharing intro on php
Ad

Viewers also liked (13)

PDF
TDC 2015 - Wearables no IoT (PT-BR)
PDF
Web Sockets - HTML5
PDF
Laravel the right way
PDF
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
PDF
TDC 2016 (Florianópolis) - Vá para o próximo nível - Dicas e truques para a c...
PDF
ZCPE - PHP Conference 2015
PDF
GDG Passo fundo - Apps with unit tests (Karma + jasmine + angular)
PDF
From legacy code to continuous integration
PDF
TDC2015 Porto Alegre - Automate everything with Phing !
PDF
Control your house with the elePHPant - PHPConf2016
PDF
Introduction to TDD (PHPunit examples)
PDF
Laravel, the right way - PHPConference 2016
PPTX
Qualitative and quantitative methods of research
TDC 2015 - Wearables no IoT (PT-BR)
Web Sockets - HTML5
Laravel the right way
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
TDC 2016 (Florianópolis) - Vá para o próximo nível - Dicas e truques para a c...
ZCPE - PHP Conference 2015
GDG Passo fundo - Apps with unit tests (Karma + jasmine + angular)
From legacy code to continuous integration
TDC2015 Porto Alegre - Automate everything with Phing !
Control your house with the elePHPant - PHPConf2016
Introduction to TDD (PHPunit examples)
Laravel, the right way - PHPConference 2016
Qualitative and quantitative methods of research
Ad

Similar to TDC São Paulo 2016 - Become a jedi with php streams (20)

ODP
C 檔案輸入與輸出
PPTX
Unix shell scripting basics
PDF
第2回 Hadoop 輪読会
PPT
Unix Shell Scripting Basics
PDF
5. Ввод-вывод, доступ к файловой системе
PDF
Module 03 File Handling in C
PPT
Unit5
PPTX
Concept of file handling in c
PPT
Php mysql
PPSX
DIWE - File handling with PHP
PPT
PDF
Java I/o streams
PPTX
Writing and using php streams and sockets
PPT
01_linux_basics tutorial for install.ppt
PPT
10.8.2018
PPT
01 linux basics
TXT
C99[2]
PPT
file handling1
KEY
PHP 5.3
PPTX
Input/Output Exploring java.io
C 檔案輸入與輸出
Unix shell scripting basics
第2回 Hadoop 輪読会
Unix Shell Scripting Basics
5. Ввод-вывод, доступ к файловой системе
Module 03 File Handling in C
Unit5
Concept of file handling in c
Php mysql
DIWE - File handling with PHP
Java I/o streams
Writing and using php streams and sockets
01_linux_basics tutorial for install.ppt
10.8.2018
01 linux basics
C99[2]
file handling1
PHP 5.3
Input/Output Exploring java.io

More from Matheus Marabesi (13)

PDF
IoT Project postmortem
PDF
Testing with Laravel - 7Masters 2018 (Laravel)
PDF
Laravel collections an overview - Laravel SP
PDF
Becoming an author - Sharing knowledge
PDF
Docker 101 - Getting started
PDF
Introduction to IoT and PHP - Nerdzão day #1
PDF
Todos os passos para a certificação PHP - PHPExperience2017
PDF
IoT powered by PHP and streams - PHPExperience2017
PDF
7masters - MongoDb
PDF
Phing - PHP Conference 2015
PDF
CK 10 - Automate all the things 2.0
PPTX
Arduino day 2015 - UFABC (PT-BR)
PPT
7º Connecting Knowledge (PT-BR)
IoT Project postmortem
Testing with Laravel - 7Masters 2018 (Laravel)
Laravel collections an overview - Laravel SP
Becoming an author - Sharing knowledge
Docker 101 - Getting started
Introduction to IoT and PHP - Nerdzão day #1
Todos os passos para a certificação PHP - PHPExperience2017
IoT powered by PHP and streams - PHPExperience2017
7masters - MongoDb
Phing - PHP Conference 2015
CK 10 - Automate all the things 2.0
Arduino day 2015 - UFABC (PT-BR)
7º Connecting Knowledge (PT-BR)

Recently uploaded (20)

PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
L1 - Introduction to python Backend.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPT
Introduction Database Management System for Course Database
PDF
System and Network Administration Chapter 2
PDF
medical staffing services at VALiNTRY
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
history of c programming in notes for students .pptx
PPTX
Introduction to Artificial Intelligence
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Nekopoi APK 2025 free lastest update
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
2025 Textile ERP Trends: SAP, Odoo & Oracle
L1 - Introduction to python Backend.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How Creative Agencies Leverage Project Management Software.pdf
Introduction Database Management System for Course Database
System and Network Administration Chapter 2
medical staffing services at VALiNTRY
Understanding Forklifts - TECH EHS Solution
Odoo POS Development Services by CandidRoot Solutions
CHAPTER 2 - PM Management and IT Context
Which alternative to Crystal Reports is best for small or large businesses.pdf
PTS Company Brochure 2025 (1).pdf.......
history of c programming in notes for students .pptx
Introduction to Artificial Intelligence
ISO 45001 Occupational Health and Safety Management System
Nekopoi APK 2025 free lastest update
VVF-Customer-Presentation2025-Ver1.9.pptx
top salesforce developer skills in 2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers

TDC São Paulo 2016 - Become a jedi with php streams