Created
August 8, 2013 10:02
-
-
Save asm89/6183370 to your computer and use it in GitHub Desktop.
Tail a file using react/socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/vendor/autoload.php'; | |
$file = __DIR__ . '/testfile'; | |
$client= popen('tail -f ' . $file, 'w'); | |
stream_set_blocking($client, 0); | |
$loop = React\EventLoop\Factory::create(); | |
$conn = new React\Socket\Connection($client, $loop); | |
$conn->pipe(new React\Stream\Stream(STDOUT, $loop)); | |
$loop->addPeriodicTimer(1, function () { | |
$memory = memory_get_usage() / 1024; | |
$formatted = number_format($memory, 3).'K'; | |
echo "Current memory usage: {$formatted}\n"; | |
}); | |
$loop->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello.
It would be possible to use this with WsServer sending the output to websocket client?
Thus websocket client would receive oos terminal real-time data