I have a php script that runs for about 2 hours. It is a cron job. The cron job runs every 4 hours.
At the end of the script, I display some memory values.
The memory_get_usage() result is 881568 Bytes (0.840766906738M)
The memory_get_peak_usage() result is 1340304 Bytes (1.27821350098M)
The memory_get_usage(true) result is 1572864 Bytes (1.5M)
The memory_get_peak_usage(true) result is 1835008 Bytes (1.75M)
The memory_limit in php.ini was 128M and it didn't work. I raise it to 256M and now it works.
But as the memory peak of the script is less than 2M....
So how does the memory_limit parameter work?
Is it the total memory used by the script? If so, how can I calculate it?
Is it the memory peak of the script? if so, am I calculating it right?
I'm using php 5.3.16.
EDIT
I don't have any error messages. When the limit was 128M The script executes, but never finishes.
memory_get_peak_usage()
instead ofmemory_get_usage()
. The latter tells you how much memory is used at the point when it's being called, while the former tells you the peak usage at any point during the script. Is there a case when..._peak_usage()
won't actually return peak usage? – Monteria