1.

Which of the following PHP functions can be used to get the current memory usage?(a) get_usage()(b) get_peak_usage()(c) memory_get_usage()(d) memory_get_peak_usage()The question was posed to me in an interview.This intriguing question originated from In-Built Functions in PHP topic in section Arrays and Functions of PHP

Answer»

Correct answer is (c) memory_get_usage()

For explanation I WOULD say: memory_get_usage() returns the amount of MEMORY, in bytes, that’s currently being allocated to the PHP script. We can set the parameter ‘real_usage’ to TRUE to get TOTAL memory allocated from system, including unused pages. If it is not set or FALSE then only the used memory is reported. To get the HIGHEST amount of memory used at any point, we can use the memory_get_peak_usage() function.



Discussion

No Comment Found

Related InterviewSolutions