PHP code example of vcn / symfony-writer
1. Go to this page and download the library: Download vcn/symfony-writer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vcn / symfony-writer example snippets
composer
namespace App;
use Symfony\Component\HttpFoundation\Response;
use Vcn\Symfony\HttpFoundation\Writer\Writer;
use Vcn\Symfony\HttpFoundation\Writer\WriterResponse;
class Controller
{
public function count(): Response
{
$response = new WriterResponse(
function (Writer $writer) {
for ($i = 0; $i < 50; $i++) {
$writer->write("{$i} ");
}
}
);
$tmpFile = tempnam(sys_get_temp_dir(), 'writer-response-');
$tmpFileHandle = fopen($tmpFile, 'w');
register_shutdown_function(
function () use ($tmpFileHandle) {
@fclose($tmpFileHandle);
}
);
error_log("Copy of response is sent to {$tmpFile}");
$response->attachListener(
function (string $data) use ($tmpFileHandle) {
fwrite($tmpFileHandle, $data);
}
);
return $response;
}
}