Guide
1
function fsockopen () has the following syntax:

fsockopen (hostname, port);

In this case, the hostname - the name of the server that is being accessed using a socket and opens a channel for data transmission.The value of port - the number that matches the port used to access the server.
2
Enter this code in your PHP file with a text editor to start the operation data exchange with the socket.For example, to connect to a specific server server.com, having a port 120, you must enter the following commands:

& lt;? Php
$ serv = "server.com";
$ serv_port = 120;
$ open_con = fsockopen ($ serv, $ serv_port);
If (! $ Open_con) {
Exit ();} Else {Echo "connection is established";
$ temporal = fgets ($ open_con, 1024);}
? & Gt;
3
This code assigns the value of the variable corresponding to the server name ($ serv) and port number ($ serv_port).If there is no connection to the server, the script stops running through the command exit ().If the connection is successful, the program displays a notification on the establishment of the connection parameters and saves it in a variable $ temporal.
4
After using fsockopen (), you can use the functions for working with files and retrieve data.So, in addition to the above fgets (), you can use fwrite () to write the file, fclose () to close or feof () to check for end of file.Thus, you can record some of the data that are transmitted by the server to which you are connected.For example:

$ data_con = "GET / HTTP / 1.1 \ r \ n";
$ data_con. = "Connection: Close \ r \ n \ r \ n";
fwrite ($ open_con, $ data_con);
$ fclose ($ open_con);
5
This query finds titles GET, given by the server, and then writes the data to disconnect from it with the appropriate parameters, written in the variable $ data_con.Stop recording file is organized using the function fclose ().
6
open sockets and recording data connection is completed.Save the file and download it for testing on your local server or hosting.