If i'm reading the code correctly, you are currently using the size of the file to check if it has changed.
However, some changes such as a single character will result in the file being the same size, but changed. I'd therefore suggest using sha($file) instead of size($file) to check if it's content has changed.
Also, you probably don't need to write the size/sha has to disk, just store it in a variable and of course don't reboot on the first check.
If i'm reading the code correctly, you are currently using the size of the file to check if it has changed.
However, some changes such as a single character will result in the file being the same size, but changed. I'd therefore suggest using sha($file) instead of size($file) to check if it's content has changed.
Also, you probably don't need to write the size/sha has to disk, just store it in a variable and of course don't reboot on the first check.