Home Menu

pfsockopen

Open persistent Internet or Unix domain socket connection

Syntax

pfsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] ) : resource

Parameters

hostname

If OpenSSL support is installed, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host.

port

The port number. This can be omitted and skipped with -1 for transports that do not use ports, such as unix://.

errno

If provided, holds the system level error number that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket.

errstr

The error message as a string.

timeout

The connection timeout, in seconds. Note: If you need to set a timeout for reading/writing data over the socket, use stream_set_timeout(), as the timeout parameter to fsockopen() only applies while connecting the socket.

Return

Examples

1

<?

$fp = pfsockopen("ssl://php.net", 443, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br>\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: php.net\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}

?>
HTTP/1.1 301 Moved Permanently
Server: myracloud
Date: Sun, 25 Jul 2021 10:30:56 GMT
Content-Type: text/html
Content-Length: 161
Connection: close
Location: https://www.php.net/

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>Myra</center>
</body>
</html>

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms