PHP fsockopen() 함수
예시
fsockopen() 예:
<?php
$fp = fsockopen("www.w3schools.com", 80, $errno, $errstr, 20);
if (!$fp) {
echo "$errstr ($errno)<br>";
} else {
$out = "GET /
HTTP/1.1\r\n";
$out .= "Host: www.w3schools.com\r\n";
$out
.= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while
(!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
정의 및 사용
fsockopen() 함수는 인터넷 또는 Unix 도메인 소켓 연결을 엽니다.
통사론
fsockopen(hostname, port, errno, errstr, timeout)
매개변수 값
Parameter | Description |
---|---|
hostname | Required. Specifies a hostname (like "www.w3schools.com"). ssl:// or tls:// works over TCP/IP to connect to the remote host |
port | Optional. Specifies the port number. Use -1 for transports that do not use ports, like unix:// |
errno | Optional. Specifies the system level error number |
errstr | Optional. Specifies the error message as a string |
timeout | Optional. Specifies the connection timeout (in seconds) |
기술적 세부 사항
반환 값: | 다른 파일 함수(예: fgets(), fwrite(), fclose())와 함께 사용할 수 있는 파일 포인터입니다. 실패시 FALSE. |
---|---|
PHP 버전: | 4.0+ |
❮ PHP 네트워크 참조