聊好的fsockopen的非阻塞模式呢?為什麼還是會阻塞

來源:互聯網
上載者:User
說好的fsockopen的非阻塞模式呢?為什麼還是會阻塞
function fsockopen_test(){
$hostname = 'm.cn';
$url = '/test/1.php';
$fp = fsockopen($hostname, 80, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)";
return false;
}
stream_set_blocking($fp,0);//開啟了手冊上說的非阻塞模式
$header = "GET $url HTTP/1.1\r\n";
$header.="Host: $hostname\r\n";
$header.="Connection: Close\r\n\r\n";//長串連關閉
fwrite($fp, $header);
fclose($fp);
}
fsockopen_test();

請求的/test/1.php裡面的代碼:
sleep(6);
$fp = fopen ( './data.txt' , 'w' );
fwrite ( $fp ,111);
fclose ( $fp );
通過瀏覽器控制台查看實際還是會等test/1.php執行完畢,這邊才重新整理。這是為什麼呢?
------解決方案--------------------
沒問題呀
echo date('Y-m-d H:i:s'), PHP_EOL;
fsockopen_test();
echo date('Y-m-d H:i:s'), PHP_EOL;
可以看到沒有延時
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.