flow php

Example: Stdout

Topic: Filesystem

Description

Stdout is a special type of filesystem allowing to write straight to stdout of the process.

Stdout is a write-only filesystem. It is not possible to read from it.

Its main purpose is to allow web servers to stream data to the client without buffering it in memory.

Code

<?php

declare(strict_types=1);

use function Flow\Filesystem\DSL\{fstab, path, protocol};

require __DIR__ . '/../../../autoload.php';

$outputStream = fstab()->for(protocol('stdout'))->writeTo(path('stdout://'));

$outputStream->append("Files List\n\n");

foreach (fstab()->for(protocol('file'))->list(path(__DIR__ . '/*')) as $file) {
    $outputStream->append(($file->isFile() ? 'File' : 'Directory') . ': ' . $file->path->basename() . "\n");
}

$outputStream->close();

Contributors

Join us on GitHub external resource
scroll back to top