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));