PHP异步
function asyncSock($url, $post=array()) { $host = parse_url($url, PHP_URL_HOST); $port = parse_url($url, PHP_URL_PORT); $port = $port ? $port : 80; $scheme = parse_url($url, PHP_URL_SCHEME); $path = parse_url($url, PHP_URL_PATH); $query = parse_url($url, PHP_URL_QUERY); if($query) { $path .= '?'.$query; } if($scheme == 'https') { $host = 'ssl://'.$host; } $fp = fsockopen($host, $port, $error_code, $error_msg, 1); if (!$fp) { return array('error_code' => $error_code, 'error_msg' => $error_msg); } else { if(empty($post)){//GET $header = "GET $path HTTP/1.1\r\n"; $header .= "Host: $host\r\n"; $header .= "Connection: close\r\n\r\n";//长连接关闭 }else{//POST $post_data = http_build_query($post); $header = "POST $path HTTP/1.1\r\n"; $header .= "Host: $host\r\n"; $header .= "Content-type: application/x-www-form-urlencoded\r\n"; $header .= "Content-length:".strlen($post_data)."\r\n"; $header .= "Connection:close\r\n\r\n"; $header .= "${post_data}"; } fwrite($fp, $header); // usleep(1000); fclose($fp); return array('error_code' => 0); } }
相关推荐
-
微信小程序实现邀请好友组队功能 php
2019-1-7
-
PHP生成自定义验证码 php
2019-1-8
-
阿里云短信接口 php
2019-1-7
-
MySQL函数过滤 php
2019-1-13
-
根据日期获取当月的开始时间和结束时间 php
2019-1-8
-
删除超时文件夹 php
2019-1-7
-
php连mysql的工具类 php
2019-1-8
-
thinkphp5,单图,多图,上传 php
2019-1-13
-
Thinkphp各大支付平台在线支付集成源码 php
2019-1-7
-
PHP封装时间类 php
2019-1-7