표준 PHP 라이브러리(SPL) SplTempFileObject::__construct
(PHP 5 >= 5.1.2, PHP 7, PHP 8)
SplTempFileObject::__construct — 새 임시 파일 객체 생성
설명
public SplTempFileObject::__construct(int $maxMemory
= 2 * 1024 * 1024)
새 임시 파일 개체를 구성합니다.
매개변수
maxMemory
- 임시 파일이 사용할 최대 메모리 양(바이트 단위, 기본값은 2MB)입니다. 임시 파일이 이 크기를 초과하면 시스템의 임시 디렉토리에 있는 파일로 이동됩니다.
maxMemory
가 음수이면 메모리만 사용됩니다.maxMemory
가 0이면 메모리가 사용되지 않습니다.
오류/예외
오류가 발생하면 RuntimeException을 던집니다.
Examples
예제 #1 SplTempFileObject() 예제
이 예제는 쓰고 읽을 수 있는 임시 파일을 메모리에 씁니다.
<?php
$temp = new SplTempFileObject();
$temp->fwrite("This is the first line\n");
$temp->fwrite("And this is the second.\n");
echo "Written " . $temp->ftell() . " bytes to temporary file.\n\n";
// Rewind and read what was written
$temp->rewind();
foreach ($temp as $line) {
echo $line;
}
?>
위의 예는 다음과 유사한 결과를 출력합니다.
Written 47 bytes to temporary file. This is the first line And this is the second.
기타
- SplFileObject
- PHP input/output streams (
php://temp
및php://memory
용)