PHP實現異步處理


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

  

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM