- fwrite: documentation ( source)
- fopen: documentation ( source)
<?php
function logger($filename) {
$fh = fopen($filename, 'w');
while (true) {
$line = yield;
fwrite($fh, $line . PHP_EOL);
}
}
$log = logger(__FILE__);
$log->send('Hello world!');