多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ <?php function requestBySock($data) { $postData = http_build_query($data); $len = strlen($postData); $host = 'localhost'; $path = '/index.php'; $errno = ''; $errnoStr = ''; $fp = fsockopen($host, 80, $errno, $errnoStr, 3); $request = "POST $path HTTP/1.1\r\n"; $request .= "Host:localhost\r\n"; $request .= "Content-type:application/x-www-form-urlencoded\r\n"; $request .= "Content-length:".$len."\r\n"; $request .= "Connection: close\r\n"; //$request .= "Expect:\r\n"; $request .= "\r\n"; $request .= $postData; fwrite($fp, $request);//提交数据 //实现异步把下面注释掉,意思是不处理返回 $receive = ''; while (!feof($fp)) { $receive .= fgets($fp, 128); } echo "<br />".$receive; //连接主动断开时,线上proxy层没有及时把请求发给上游 usleep(10000); fclose($fp); } $postData = array( "title" => "woshisocket", "content" => "tijiao", ); requestBySock($postData); ?> ~~~