라이브러리

[PHP] LuaSandbox::getCPUUsage - Lua 환경의 현재 CPU 시간 사용량을 가져옵니다.




LuaSandbox::getCPUUsage


LuaSandbox는 PHP에서 Lua를 실행할 수 있는 라이브러리로, Lua의 CPU 사용률을 측정하는 `getCPUUsage` 메소드를 제공합니다. 이 메소드는 LuaSandboxes의 CPU 사용률을 백분율로 반환합니다.

사용 방법


LuaSandbox::getCPUUsage 메소드를 사용하려면 먼저 LuaSandbox를 설치하고, LuaSandboxes를 생성한 후에 사용할 수 있습니다.

#hostingforum.kr
php

require 'LuaSandbox.php';



$sandbox = new LuaSandbox();

$sandbox->loadString('while true do end');

echo $sandbox->getCPUUsage();



예제


# 예제 1: CPU 사용률 측정


#hostingforum.kr
php

require 'LuaSandbox.php';



$sandbox = new LuaSandbox();

$sandbox->loadString('while true do end');



$cpuUsage = $sandbox->getCPUUsage();

echo "CPU 사용률: $cpuUsage%";



# 예제 2: CPU 사용률 측정 및 로그 기록


#hostingforum.kr
php

require 'LuaSandbox.php';



$sandbox = new LuaSandbox();

$sandbox->loadString('while true do end');



$cpuUsage = $sandbox->getCPUUsage();

echo "CPU 사용률: $cpuUsage%";



// 로그 기록

$file = fopen('cpu_usage.log', 'a');

fwrite($file, date('Y-m-d H:i:s') . " CPU 사용률: $cpuUsage%
");

fclose($file);



참고


* LuaSandbox는 PHP 5.3 이상에서 작동합니다.
* LuaSandbox::getCPUUsage 메소드는 LuaSandboxes의 CPU 사용률을 백분율로 반환합니다.
* CPU 사용률은 백분율로 표시됩니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색