If this script MUST ABSOLUTELY RUN without using a known/ existing solution (such as wtmp), you should memory mapmmap(...) directive the file and read with append. This will return the next value pretty much instantaneously while not polling to maximize efficiency. There is probably a Module ofr this somewhere...