Answer the question
In order to leave comments, you need to log in
How to listen to a file in realtime?
Actually, the user data is written to the file using the utility. On the same server, I wrote an api that accepts logs. Is it possible to somehow implement that with each update of the file, or even simply, without a file, send data to the address of my api?
Answer the question
In order to leave comments, you need to log in
for a file, the simplest option would be to implement behavior similar to the tail utility, or call tail and take the output from it
$handle = popen("tail -f /path/to/my/logfile.log 2>&1", 'r');
while(!feof($handle)) {
$buffer = fgets($handle);
// здесь будет вызов API
ob_flush();
flush();
}
pclose($handle);
Well, at least the question was answered, but I'll add it. Linux has an inotify subsystem that allows you to monitor a file in real time - https://en.wikipedia.org/wiki/Inotify
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question