Hàm fsockopen() của PHP
Ví dụ
ví dụ về fsockopen():
<?php
$fp = fsockopen("www.example.com.vn", 80, $errno, $errstr, 20);
if (!$fp) {
echo "$errstr ($errno)<br>";
} else {
$out = "GET /
HTTP/1.1\r\n";
$out .= "Host: www.example.com.vn\r\n";
$out
.= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while
(!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
Định nghĩa và cách sử dụng
Hàm fsockopen() mở kết nối ổ cắm miền Internet hoặc Unix.
Cú pháp
fsockopen( hostname , port, errno, errstr, timeout )
Giá trị tham số
Parameter | Description |
---|---|
hostname | Required. Specifies a hostname (like "www.example.com.vn"). 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) |
Chi tiết kỹ thuật
Giá trị trả về: | Một con trỏ tệp có thể được sử dụng với các hàm tệp khác (chẳng hạn như fgets(), fwrite(), fclose()). FALSE khi thất bại. |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu mạng PHP