라이브러리

[PHP] memory_get_usage - PHP에 할당된 메모리 양을 반환합니다.




PHP의 memory_get_usage 함수


PHP의 `memory_get_usage` 함수는 현재 프로세스의 메모리 사용량을 반환하는 함수입니다. 이 함수는 PHP 4.x 부터 사용할 수 있으며, PHP 5.x 부터는 `memory_get_usage(true)` 형태로 사용할 수 있습니다.

# 기본 사용법


`memory_get_usage` 함수는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

$memory_usage = memory_get_usage();

echo "현재 메모리 사용량 : $memory_usage bytes";



# true 매개변수 사용법


`memory_get_usage` 함수의 `true` 매개변수는 프로세스의 전체 메모리 사용량을 반환합니다.

#hostingforum.kr
php

$memory_usage = memory_get_usage(true);

echo "현재 프로세스 전체 메모리 사용량 : $memory_usage bytes";



# 예제


다음 예제는 `memory_get_usage` 함수를 사용하여 현재 프로세스의 메모리 사용량을 측정하는 방법을 보여줍니다.

#hostingforum.kr
php

<?php



// 메모리 사용량 측정

$memory_usage = memory_get_usage();

echo "현재 메모리 사용량 : $memory_usage bytes
";



// 메모리 사용량 측정 (전체 프로세스)

$memory_usage_total = memory_get_usage(true);

echo "현재 프로세스 전체 메모리 사용량 : $memory_usage_total bytes
";



// 메모리 사용량 측정 (전체 프로세스, 단위 바이트)

$memory_usage_total_bytes = memory_get_usage(true) / 1024;

echo "현재 프로세스 전체 메모리 사용량 (KB) : $memory_usage_total_bytes KB
";



// 메모리 사용량 측정 (전체 프로세스, 단위 메가바이트)

$memory_usage_total_mb = memory_get_usage(true) / (1024 * 1024);

echo "현재 프로세스 전체 메모리 사용량 (MB) : $memory_usage_total_mb MB
";



?>



# 참고


* `memory_get_usage` 함수는 프로세스의 메모리 사용량을 측정하는 데 사용할 수 있습니다.
* `true` 매개변수를 사용하면 프로세스의 전체 메모리 사용량을 반환할 수 있습니다.
* 메모리 사용량을 측정할 때는 `memory_get_usage` 함수를 사용할 수 있습니다.
* 메모리 사용량을 단위별로 측정할 때는 `memory_get_usage` 함수를 사용할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 411 페이지

검색

게시물 검색