php - How to get notification when a new text is added to a file?
There is a text file that errors from a script will be saved into.
Each error on a new line, Then these errors will be shown on a new admin menu.
Here is the code to save the errors:
$error = 'Error Message'; file_put_contents('erros.txt', $error.PHP_EOL , FILE_APPEND | LOCK_EX);
Getting the errors from that text file:
My question is how to create a notification when a new error is thrown to that file?
Something like when a new WordPress update, Or stackoverflow notifications.
Should I for example add some code beneath the
file_put_contants() function that creates the notification?
It doesn't be so fancy, Maybe just a red element without numbers, Something that tells there is a new text added.
The first thing that comes into my mind: use an alias for file_put_contents and whenever you add text to the file you insert a value in a DB. At this point it is "easy" to know how many unread notifications you have.
you could use filemtime to see if the file got modified since last check