0

I have a PHP-script that parses logfiles from my server. At the moment the data is written in an array and printed. Later, the data will be saved in an MySQL-Database.

The problem is, that the array with the is never larger than 1893, which is only a small part of the data. The number didn't change after I increased the memory_limit from 128M to 512M. I'm absolutely sure, that all logs are processed.

Is there a limit for arrays?

Or is there a problem with my code. Every log-file is parsed into an array ($result) which is appended to the final array ($allResults).

$allResults = $allResults+$result;
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
  • A few thoughts, If you are reading all the files, it will be using double the amount of memory while it loads them all. Perhaps you are hitting the max execution time? – NickOS Dec 10 '15 at 05:12
  • (depending on how your environment is set, you may need to restart apache) – NickOS Dec 10 '15 at 05:18

2 Answers2

4

There should not be a limit to the size of an array in PHP except for running out of memory.

I've not used that notation for appending arrays to each other and I don't think it does what you are trying to do. Have you tried you code with:

$allResults = array_merge($allResults, $result);

You may also just be having the script time out depending on the size of the files and the server load.

If you have not you could add this to the top of the page to see what the full errors are:

ini_set("display_errors", "1");
error_reporting(E_ALL);
DjB
  • 116
  • 4
  • Thank you! :-) The _max\_execution\_time_ was not reached, because the script failed because of my notation to merge the arrays. It works with an execution time of 120 seconds. – FelixSFD Dec 10 '15 at 06:33
1

In php array, "+" operator is not as array_merge, You can refer to "+ operator in php". Here I recommend you use array_merge:

$allResults = array_merge($allResults,$result);
FisherMartyn
  • 826
  • 1
  • 8
  • 17