123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace demo\Controllers;
- use Silex\Application;
- use Symfony\Component\HttpFoundation\Response;
- /**
- * Class StreamController demos streaming of static files and custom content.
- *
- * @package demo\Controllers
- */
- class StreamController {
- public function customStream(Application $app) {
- $noise = base64_encode(random_bytes(2048));
- $stream = fopen('php://memory', 'r+');
- fwrite($stream, $noise);
- rewind($stream);
- $streamer = function () use($stream) {
- while (!feof($stream)) {
- echo fread($stream, 1024);
- ob_flush();
- flush();
- }
- fclose($stream);
- };
- return $app->stream($streamer, Response::HTTP_OK, ['Content-type' => 'text/plain']);
- }
- public function fileStream(Application $app) {
- return $app->sendFile('/etc/passwd');
- }
- }
|