• PHP Video Tutorials

PHP - Function pfsockeopen



Syntax

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

Definition and Usage

It used to open internet or unix domain socket

Return Values

If Connection is successful it may returns fgets(), fgetss(), fwrite(), fclose(), and feof() or else it will give False on failure case

Parameters

Sr.No Parameters & Description
1

hostname

It contains the host name information.

2

port

It contains the port number.

3

errno

It provides the system level of error information.

4

errstr

It contains error message as a string

5

timeout

It contains the connection time out information.

Example

Try out following example

<?php
   $open = fsockopen("www.tutorialspoint.com", 80, $errno, $errstr, 30);
   
   if (!$open) {
      echo "$errstr ($errno)
      \n";
   } else {
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: www.tutorialspoint.com\r\n";
   $out .= "Connection: Close\r\n\r\n";
   
   fwrite($open, $out);
   
   while (!feof($open)) {
      echo fgets($open, 128);
   }
   
   fclose($open);

?>
php_function_reference.htm
Advertisements