首先需要php支持fsockopen php.ini文件中查找
allow_url_fopen = Onpublic function requestBySock($data){ $len = strlen($data); $host = 'localhost'; $path = '/test.php'; $fp = fsockopen($host , 80, $errno, $errstr, 3); if ($fp) { $out = "POST $path HTTP/1.1/r/n"; $out .= "Host: $host/r/n"; $out .= "Content-type: application/x-www-form-urlencoded/r/n"; $out .= "Content-Length: $len/r/n"; $out .= "Connection: close/r/n"; //$out .= "Expect:/r/n"; $out .= "/r/n"; $out .= $data."/r/n"; fwrite($fp, $out); //實現異步把下面注釋掉,意思是不處理返回 // $receive = ''; // while (!feof($fp)) { // $receive .= fgets($fp, 128); // } // echo "<br />".$receive; //連接主動斷開時,線上PRoxy層沒有及時把請求發給上游 usleep(10000); fclose($fp); }}新聞熱點
疑難解答
圖片精選