Home  >  Article  >  Backend Development  >  How to solve the problem of fsockopen php operation failure

How to solve the problem of fsockopen php operation failure

藏色散人
藏色散人Original
2021-07-16 09:24:422994browse

The fsockopen php operation failed because of a server setting problem and localhost was not monitored. The solution is to reset the server network environment.

How to solve the problem of fsockopen php operation failure

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

Specific questions:

php fsockopen local error? How to solve the problem of fsockopen php operation failure?

An error occurred when using fsockopen to make an asynchronous call. The same code did not cause problems under Alibaba Cloud centos and Tencent Cloud win2008.

Write the host address to 127.0.0.1 or localhost appears:

Warning: fsockopen(): Unable to connect because the target machine actively refuses. (10061)

host writes the current server domain name and appears:

Warning: fsockopen(): The connection attempt failed because the connecting party did not reply correctly after a period of time or the connected host did not respond. (10060)

host address The current server internal network IP is such as 192.168.3.3. The response is normal and there is no error.

Moreover, there is no problem when the server fsockopens to other servers or when other servers want to fsockopen the server and can be sent normally.

The code is as follows:

function async_post($host,$path,$data){
    $post = http_build_query($data);
    $len = strlen($post);
    $fp = fsockopen( $host , 80, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)\n";
    } else {
        $out = "POST $path HTTP/1.1\r\n";
        $out .= "Host: $host\r\n";
        $out .= "Content-type: application/x-www-form-urlencoded\r\n";
        $out .= "Connection: Close\r\n";
        $out .= "Content-Length: $len\r\n";
        $out .= "\r\n";
        $out .= $post."\r\n";
        fwrite($fp, $out);
        fclose($fp);
    }
}

is ultimately called through the intranet IP, but why is this?

Solution:

The source of the problem has been found:

Server setting problem, not listening to localhost

Server network environment, no I know which network administrator did it. The server cannot access itself through the external IP.

As a result, fsockopen can only be accessed through 192.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve the problem of fsockopen php operation failure. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn