PSL 5.3.0
New: IO\spool()
Create a handle that writes to memory until a threshold is reached, then transparently spills to a temporary file on disk. Useful for buffering data of unknown size without risking excessive memory usage.
use Psl\IO;
$handle = IO\spool(); // default 2MB threshold
$handle->writeAll($data);
$handle->seek(0);
$contents = $handle->readAll();
$handle->close();
// Custom threshold: spool to disk after 64 bytes
$small = IO\spool(maxMemory: 64);The returned handle implements CloseHandleInterface, SeekHandleInterface, ReadHandleInterface, WriteHandleInterface, and StreamHandleInterface.
Documentation: psl.carthage.software/5.3.0/ | IO
Full Changelog: 5.2.0...5.3.0