PHP code example of jalsoedesign / log-stream

1. Go to this page and download the library: Download jalsoedesign/log-stream 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/ */

    

jalsoedesign / log-stream example snippets


use jalsoedesign\LogStream\LogStream;

t');

// OR

$handle = fread('foo.txt', r);
$stream = new LogStream($handle);

$stream = LogStream::fromPath('foo.txt');

echo 'The first 10 lines:' . PHP_EOL;
echo $stream->readLines(10);

$stream = LogStream::fromPath('foo.txt');

echo 'The first 10 lines:' . PHP_EOL;
print_r($stream->getLines(10));

$stream = LogStream::fromPath('foo.txt');

echo 'The last 10 lines:' . PHP_EOL;
echo $stream->readLines(-10);

$stream = LogStream::fromPath('foo.txt');

echo 'The last 10 lines:' . PHP_EOL;
print_r($stream->getLines(-10));

$stream = LogStream::fromPath('foo.txt');

$logStream->seekLines(-10);

$running = true;

echo 'The last 10 lines as well as all new content:' . PHP_EOL;

do {
    echo $logStream->readIncremental();

    usleep(100000);
} while ($running);

$stream = \LogStream::fromPath('foo.txt');

$logStream->seekReset();

$running = true;

echo 'New file content:' . PHP_EOL;

do {
    echo $logStream->readIncremental();

    usleep(100000);
} while ($running);