resource fsockopen ( string $hostname
[, int $port
= -1 [, int &$errno
[, string &$errstr
[, float $timeout
= ini_get("default_socket_timeout") ]]]] )
参数
hostname
如果安装了OpenSSL,那么你也许应该在你的主机名地址前面添加访问协议ssl://或者是tls://,从而可以使用基于TCP/IP协议的SSL或者TLS的客户端连接到远程主机。
port
端口号。如果对该参数传一个-1,则表示不使用端口,例如unix://。
errno
如果传入了该参数,holds the system level error number that occurred in the system-level connect() call。
如果
errno
的返回值为0,而且这个函数的返回值为FALSE
,那么这表明该错误发生在套接字连接(connect())调用之前,导致连接失败的原因最大的可能是初始化套接字的时候发生了错误。errstr
错误信息将以字符串的信息返回。
timeout
设置连接的时限,单位为秒。
lg: ww.php
$fp = fsockopen($_SERVER[‘HOST‘],80);if(!$fp){}else{ ???$param = array( ???????‘name‘ => ‘fdipzone‘, ???????‘gender‘ => ‘man‘, ???????‘photo‘ => file_get_contents(‘photo.jpg‘) ???); ???$data = http_build_query($param); ???$out = "POST /api/im-wa/new ??HTTP/1.1\r\n"; ?//模拟POST请求 ???$out .= "Host: www.example.com\r\n"; ???$out .= "Content-Type: application/x-www-form-urlencoded\r\n";//POST数据 ???$out .= "Content-Length: ". strlen($data) ."\r\n";//POST数据的长度 ???$out.="Connection: Close\r\n\r\n";//长连接关闭 ???$out .= $data; //传递POST数据 ???stream_set_blocking($fp,true); ???stream_set_timeout($fp,1); ???fwrite($fp, $out); ???usleep(1000); ???fclose($fp);}
wa.php
file_put_contents(‘1.txt‘,json_encode($_POST));
PHP实现异步处理
原文地址:https://www.cnblogs.com/sunshenggang/p/9007566.html