One, how to disable Fsockopen ()
The following are two common methods for disabling Fsockopen.
1, modify php.ini, add disable_functions = add fsockopen
2, modify php.ini, Allow_url_ fopen = on changed to allow_url_fopen = off
Ii. How to resolve the Fsockopen function is disabled
1, if the server does not disable Pfsockopen at the same time, then directly replace the Fsockopen function with Pfsockopen.
What to do: Search for a string fsockopen in the program (replaced by Pfsockopen (. Example below
Before modification:
$fp = Fsockopen ($host, $errno, $errstr, 30);
After modification:
$fp = Pfsockopen ($host, $errno, $errstr, 30);
2, if the server also disables the Pfsockopen, then replace with other functions, such as stream_socket_client (). Note: The parameters for Stream_socket_client () and Fsockopen () are different.
What to do: Search the string Fsockopen in the program (replace with Stream_socket_client (), then delete the port parameter "80" in the original Fsockopen function and add it to the $host. Example below
Before modification:
$fp = Fsockopen ($host, $errno, $errstr, 30);
After modification
$fp = Stream_socket_client ($host.) ", $errno, $errstr, 30);
3, if PHP version below 5.0,fsockopen is disabled, and there is no stream_socket_client () How to do? Write a function of your own to implement Fsockopen function, reference code:
Copy Code code as follows:
function B_fsockopen ($host, $port, & $errno, & $errstr, $timeout) {
$ip = gethostbyname ($host);
$s = socket_create (af_inet, sock_stream, 0);
if (Socket_set_nonblock ($s)) {
$r = @socket_connect ($s, $ip, $port);
if ($r | | socket_last_error () = einprogress) {
$errno = einprogress;
return $s;
}
}
$errno = Socket_last_error ($s);
$errstr = Socket_strerror ($errno);
Socket_close ($s);
return false;
}
Specific operation: 1. First find the Use FsockopenThe code snippet for the function, add the code above to its upper end, and search for the string in the code snippet Fsockopen (Replaced by B_fsockopen (。
2. Because the Fsockopen function returns a file pointer, it can be manipulated by a file function, but this B_fsockopenFunction failed to return the file pointer, you need to continue modifying the code snippet: Socket_read(replace Fread (Use Socket_write (Replace fwrite (Use Socket_close (Replace fclose (。