0

Help me, please.

When I'm trying to read a file using

$tmp = file('file.log');

I get an error

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 90 bytes) in script.php on line 37

php memory limit is 128M, size of file.log is only 48M.

Vasily
  • 27
  • 2
  • Do you really need to whole file at a time? – Gumbo Jul 20 '13 at 15:52
  • Gumbo, I need to read last N lines of a big file. How can I do it without reading all file? – Vasily Jul 20 '13 at 16:30
  • 2
    No need to read the whole file into memory. The overhead might come from turning it into one large array. You should use fgets/fgetc and fseek for things like this http://stackoverflow.com/questions/1510141/read-last-line-from-file – tlenss Jul 20 '13 at 16:41

1 Answers1

0

It seems that something have consumed some amount of memory before. You allocate 128M for all operations, data and so on in your script. And memory has finished in this place only because your script exceeded it trying to sum, for example, 87M(uses by something earlier)+48M(your file).

Andrej
  • 7,474
  • 1
  • 19
  • 21