English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The pfsockopen() function opens a persistent network connection or Unix domain socket connection.
resource pfsockopen(string $hostname[, int $port = -1 [, int &$errno[, string &$errstr[, float $timeout = ini_get("default_socket_timeout")]]])
It is used to open Internet or Unix domain sockets
If the connection is successful, it may return fgets(), fgetss(), fwrite(), fclose(), and feof(), otherwise it will return False in the case of failure.
This function works exactly the same as fsockopen(), the difference is that the connection will not be closed after the script execution is completed. It can be said that it is the long connection version of fsockopen().
Serial Number | Parameters and Description |
---|---|
1 | hostname It contains hostname information. |
2 | port It contains the port number. |
3 | errno It provides system-level error information. |
4 | errstr It contains error messages as strings. |
5 | timeout It contains connection timeout information. |
Try the following example
<?php $open = fsockopen("www.w"3codebox.com", 80, $errno, $errstr, 30); if (!$open) { echo "$errstr ($errno" \n" } else { $out = "GET" / HTTP/1.1\r\n" $out .= "Host: www.w"3codebox.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($open, $out); while (!feof($open)) { echo fgets($open, 128); } fclose($open); ?>