fsockopen fwrite 模擬瀏灠器動作

liang | 2010-02-23 15:48:02 | PHP


<?php

$uri=array(

        "www.facebook.com"=>"/index.cfm",

        "tw.yahoo.com"=>"/index.cfm",

        );

echo date("Y-m-d H:i:s")."<BR>";

$str1="";

foreach($uri as $url => $file){

    list($startusec, $startsec) = explode(" ", microtime());

    $conn_status="Connect fail!";

    $header=null;

    $sock = fsockopen($url, 80);

    if ($sock)

    {

        $conn_status="Connect OK!";

        fwrite($sock, "GET $file HTTP/1.0\r\n");

        fwrite($sock, "HOST: $url\r\n");

        fwrite($sock, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n\r\n");

        fwrite($sock, "Connection: Close\r\n\r\n");

        while(!feof($sock)) {

            $header[]=fgets($sock);

        }

    }

    list($endusec, $endsec) = explode(" ", microtime());

    $sec=$endsec-$startsec;

    $usec=$endusec-$startusec;

    $time=$sec+$usec;

    $str1.="<tr><td>&nbsp;".$url."</td><td>".$file."</td>";

    $str1.="<td>&nbsp;".$conn_status."</td>";

    $str1.="<td>&nbsp;".$time."s</td>";

    $str1.="<td>&nbsp;".$header[0]."</td></tr>";

}

echo "<html><head></head><body><table>".$str1."</table></body></html>";

?>


========================================================================

相關文章

php : array write to file (陣列存放在檔案裡) AND parse_ini_file
SVN 只匯出該版號有異動的檔案
PHP5 連線 Oracle -- 初體驗
[ 轉 ] ubuntu下利用php+sphinx構建搜索引擎,在ubuntu 8.04 64位系統下測試通過
fsockopen fwrite 模擬瀏灠器動作
PHP 時間的加減
[ 轉 ] 利用javascript 取得 GET 變數
[ 轉 ] FLV 影片轉檔
Cannot modify header information - headers already send
[ 轉 ] 使用SWFTools把PDF轉成可以瀏覽的SWF檔案

意見反應

發表意見

*匿稱

電子郵件

*內容

.

 
'*'請輸入驗證碼:
'*'為必填欄位.(If content include "href" be Deny)