简体   繁体   中英

How does fsockopen work in php

I am very new to socket programming. I saw a bit of code like

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

At end i see its doing a fwrite. My question is how does it execute the remote php code using fwrite.

This code is connecting to a webserver, and sending an HTTP request, just like a browser would. The remote code executes because that's what the webserver is configured to do when you request that document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM