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));
来源: http://www.bubuko.com/infodetail-2592054.html