Lab 08: Streams & Context
Step 1: Built-in Stream Wrappers
<?php
// php://memory — RAM buffer, never touches disk
$mem = fopen('php://memory', 'r+');
fwrite($mem, 'Hello World from PHP streams!');
rewind($mem);
echo stream_get_contents($mem) . "\n";
fclose($mem);
// php://temp — RAM up to 2MB, then spills to disk
$tmp = fopen('php://temp', 'r+');
fwrite($tmp, 'Temporary data: ' . str_repeat('X', 100));
rewind($tmp);
echo 'Temp size: ' . strlen(stream_get_contents($tmp)) . " bytes\n";
fclose($tmp);
// php://input (read-only) / php://output (write-only) — used in web context
// php://stdin, php://stdout, php://stderr
// data:// wrapper — inline data URI
$inline = fopen('data://text/plain,Hello%20Inline!', 'r');
echo stream_get_contents($inline) . "\n";
fclose($inline);Step 2: Stream Contexts for HTTP
Step 3: Reading URLs with file_get_contents
Step 4: Stream Filters
Step 5: Zlib Compression Filter
Step 6: Custom Stream Filter
Step 7: Custom Stream Wrapper
Step 8: Capstone — Streaming ETL Pipeline with Filters
Summary
Feature
Function/Class
Use Case
Last updated
