This PHP script adds lines into my text file (log):
file_put_contents($filename, $log .PHP_EOL, FILE_APPEND | LOCK_EX);
I am limiting log files to stay within 100Mb, thereafter a new file will be created; thus I expect aprox. 144 bytes per line and around 750000 lines per file.
I need to log actions and I need to log them fast. Does anyone know if file_put_contents
performance will progressively be slower with such big files?
Maybe they are not big in size but certainly are big in the number of lines.
---- Update: ----
Based on Cully Larson suggestion here is the results of how much time file_put_contents took to write the exact same $string into a plain-text file. I am running WAMP server for Windows.
Line 000001 150bytes --> 0.00046801567077637 seconds
Line 000002 150bytes --> 0.00022101402282715 seconds
Line 000003 150bytes --> 0.00019407272338867 seconds
...
Line 000010 150bytes --> 0.00016212463378906 seconds
...
Line 000100 150bytes --> 0.00015997886657715 seconds
...
Line 001000 150bytes --> 0.00015687942504883 seconds
...
Line 010000 150bytes --> 0.00016403198242188 seconds
...
Line 100000 150bytes --> 0.00016617774963379 seconds
...
Line 250000 150bytes --> 0.0001678466796875 seconds
...
Line 500000 150bytes --> 0.00016283988952637 seconds
...
Line 750000 150bytes --> 0.00020289421081543 seconds
EOF!
Hope this information helps someone else too.
does not matter. You are doing append, not read-write.