Streams stream_set_timeout
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
stream_set_timeout — Set timeout period on a stream
설명
stream_set_timeout(resource $stream
, int $seconds
, int $microseconds
= 0): bool
seconds
와 microseconds
의 합계로 표시되는 stream
의 시간 초과 값을 설정합니다.
스트림 시간이 초과되면 stream_get_meta_data()가 반환하는 배열의 'timed_out' 키가 true
로 설정되지만 오류/경고는 생성되지 않습니다.
매개변수
stream
- 대상 스트림.
seconds
- 설정할 시간 제한의 초 부분입니다.
microseconds
- 설정할 시간 제한의 마이크로초 부분입니다.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
Examples
예제 #1 stream_set_timeout() 예제
<?php
$fp = fsockopen("www.example.com", 80);
if (!$fp) {
echo "Unable to open\n";
} else {
fwrite($fp, "GET / HTTP/1.0\r\n\r\n");
stream_set_timeout($fp, 2);
$res = fread($fp, 2000);
$info = stream_get_meta_data($fp);
fclose($fp);
if ($info['timed_out']) {
echo 'Connection timed out!';
} else {
echo $res;
}
}
?>
메모
메모: 이 함수는 stream_socket_recvfrom()과 같은 고급 작업에서는 작동하지 않습니다. 대신 timeout 매개변수와 함께 stream_select()를 사용하세요.
이 함수는 이전에 set_socket_timeout() 및 이후 socket_set_timeout()으로 호출되었지만 이 사용법은 더 이상 사용되지 않습니다.
기타
- fsockopen() - 인터넷 또는 Unix 도메인 소켓 연결 열기
- fopen() - 파일 또는 URL을 엽니다.