???本文筆者是一個php初學者,下面是我一些筆記總結:

          1.測試一個網站的負載量:
          進入apache路徑下的bin目錄,比如我們要測試“同時處理50個請求并運行 1000 次 ab -c 50 -n 1000

          http://localhost/phpinfo.php

          2.判斷某個站點能不能打開:

          fsockopen(string hostname, int port, int , string , int );
          $fp = fsockopen("php.wilson.gs", 80, &$errno, &$errstr, 10);
          if(!$fp) {
          echo "$errstr ($errno)<br/>\n";
          } else {
          fputs($fp,"get / http/1.0\nhost: php.wilson.gs\n\n");
          while(!feof($fp)) {
          echo fgets($fp,128);
          }
          fclose($fp);
          }

          ************
          ?下面的代碼是正確的,返回了www.nic.edu.cn的首頁
          <?php $fp = fsockopen("

          ($errno)<br>\n"; } else { while(!feof($fp)) { echo fgets($fp,128); } fclose($fp); } ?>

          但是問題是我想要得是:
          http://www.nic.edu.cn/RS/ipstat/internalip/index.html 但我將上面的代碼改成

          :fsockopen("

          錯誤:(0). 要想得到:http://www.nic.edu.cn/RS/ipstat/internalip/index.html 我該如何做?

          ************
          建立server的socket連接跟HTTP沒有關系 不能在主機IP后面加路徑.

          ***********
          我覺得獲取遠程網頁 用fopen就可以了.

          <?php
          ?$fp = fopen("
          ?if(!$fp)
          ?{
          ??echo "N";
          ?}
          ?else
          ?{
          ??echo "Y";
          ?}
          ?>

          3.php重定向

          echo "<script language=javascript>";
          echo "document.location.href='xxxx.php";
          echo </script>"; 響應者 3:<?php
          header("location:

          /* 確保重定向后,后續代碼不會被執行 */
          exit;
          ?>

          <?php
          header("location;http://www.****.com");
          ?>

          <?php
          echo "<meta http-equals=refresh content='0;url=http://www.***.com'>";
          ?>

          4.php 獲取當前絕對路徑
          <?php
          ??????? echo $_SERVER["DOCUMENT_ROOT"];
          ?>
          jsp獲取當前絕對路徑
          String path = request.getRealPath("");

          5.模擬HTTP 連線
          <?php??
          ? $fp?? =?? fsockopen("
          www.aygfsteel.com",?? 80,?? &$errno,?? &$errstr,?? 10);??
          ? if(!$fp)?? {??
          ????????????????? echo?? "$errstr?? ($errno)<br>\n";??
          ? }?? else?? {??
          ????????????????? fputs($fp,"GET?? /?? HTTP/1.0\nHost:?? www.aygfsteel.com\n\n");??
          ????????????????? while(!feof($fp))?? {??
          ????????????????????????????????? echo?? fgets($fp,128);??
          ????????????????? }??
          ????????????????? fclose($fp);??
          ? }??
          ? ?>??

          5.print_r(HTTPrequest('get',?? 'www.w3.org',?? '/'));?

          沒有二級域名 以/代替

          6.PHP 模擬POST GET

          <?php
          ?print_r(HTTPrequest

          ('post','lnc.ep.duba.net','/***.aspx','ksn=*****));??
          ?function HTTPrequest($method,$host,$usepath,$postdata = "")??
          ?{??
          ??if(is_array($postdata))??
          ??{??
          ???foreach($postdata as $key=>$val)?
          ???{??
          ????if(!is_integer($key))??
          ????$data? .=? "&$key=".urlencode($val);??
          ???}??
          ???$data = substr($data,1);??
          ??}
          ??else??
          ??{??
          ???$data = $postdata;??
          ??}??
          ??$fp = fsockopen($host, 80, &$errno, &$errstr, 30);??
          ??if(!$fp)
          ??{??
          ???print "$errstr ($errno)<br>\n";??
          ???return false;??
          ??}??
          ??else
          ??{??
          ???if(strtoupper($method) == "GET")
          ???{??
          ????$headers = "GET $usepath HTTP/1.1\r\n";??
          ???}
          ???else if(strtoupper($method) == "POST")
          ???{??
          ????$headers = "POST $usepath HTTP/1.1\r\n";??
          ???}??
          ????$headers .= "Host:?? $host\n";??
          ????$headers .= "Connection:?? close\r\n";??
          ???//$headers?? .=?? "Accept-Encoding:?? gzip\r\n";??
          ???if(strtoupper($method) == "POST")??
          ???{??
          ????$strlength?? =?? strlen($data);??
          ????$headers?? .=?? "Content-Type:?? application/x-www-form-

          urlencoded\r\n";??
          ????$headers?? .=?? "Content-Length:?? ".$strlength."\r\n";??
          ???}??
          ???$headers?? .=?? "\r\n";??
          ???$headers?? .=?? "$data\r\n";??
          ???fputs($fp,?? $headers);??
          ???while(!feof($fp))??
          ???{??
          ????$output[]?? =?? fgets($fp,?? 1024);??
          ???}??
          ???fclose(?? $fp);??
          ???return?? $output;??
          ??}??
          ?}??
          ?>

          7.逐行讀取文件

          <?php
          $handle = @fopen("/tmp/inputfile.txt", "r");
          if ($handle) {
          ??? while (!feof($handle)) {
          ??????? $buffer = fgets($handle, 4096);
          ??????? echo $buffer;
          ??? }
          ??? fclose($handle);
          }
          ?>

          8.取當前路徑
          echo?? dirname($_SERVER['SCRIPT_FILENAME']);??
          :D:/kingsoft/KAN5/CONSOLE/trunk/src/V5WebConsole
          echo $_SERVER['PHP_SELF'];
          :/test.php

          posted on 2007-12-24 01:56 -274°C 閱讀(813) 評論(3)  編輯  收藏 所屬分類: PHP


          FeedBack:
          # re: PHP初學者總結
          2008-01-02 15:28 | 小河
          9.獲取ip

          function get_client_ip()
          {
          global $_SERVER;
          if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
          {
          $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
          }
          elseif(isset($_SERVER["HTTP_CLIENT_IP"]))
          {
          $realip = $_SERVER["HTTP_CLIENT_IP"];
          }
          else
          {
          $realip = $_SERVER["REMOTE_ADDR"];
          }
          return $realip;
          }  回復  更多評論
            
          # re: PHP初學者總結
          2008-01-03 15:31 | java-he
          10.得到瀏覽器版本,得到操作系統語言:
          <?php
          echo $_SERVER['HTTP_USER_AGENT'];
          echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];
          // print_r($_SERVER);
          ?>   回復  更多評論
            
          # re: PHP初學者總結
          2008-02-26 15:15 | java-he
          11.iconv()與mb_convert_encoding() 區別

          iconv() 函數
          Definition and Usage
          定義和用法
          iconv()函數的作用是:轉換字符串的編碼。

          Description
          string iconv ( string in_charset, string out_charset, string str )

          Tips and Notes
          注意點
          注意:第二個參數,除了可以指定要轉化到的編碼以外,還可以增加兩個后綴://TRANSLIT 和 //IGNORE,其中 //TRANSLIT 會自動將不能直接轉化的字符變成一個或多個近似的字符,//IGNORE 會忽略掉不能轉化的字符,而默認效果是從第一個非法字符截斷。

          mb_convert_encoding() 函數
          Definition and Usage
          定義和用法
          mb_convert_encoding()函數的作用是:轉換字符串的編碼。

          Description
          string mb_convert_encoding ( string str, string to-encoding [, mixed from-encoding])
          注意:但是需要先enable mbstring 擴展庫。

          兩者區別:mb_convert_encoding 中根據內容自動識別編碼;mb_convert_encoding功能強大,但是執行效率比iconv差太多;

          總結:一般情況下用 iconv,只有當遇到無法確定原編碼是何種編碼時才用 mb_convert_encoding 函數.

          <code>
          $str = iconv("UTF-8","GB2312//TRANSLIT",$str);
          </code>
            回復  更多評論
            

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網站

          關注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 914107
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 屏山县| 绩溪县| 安化县| 大荔县| 东源县| 三门县| 额济纳旗| 通海县| 巨鹿县| 黔东| 麦盖提县| 汤原县| 磐安县| 绥化市| 威宁| 施秉县| 绵竹市| 吉安县| 嘉祥县| 咸丰县| 凌源市| 通道| 荣昌县| 浦北县| 响水县| 乌苏市| 郯城县| 九龙城区| 梧州市| 遂平县| 山阴县| 韩城市| 寿阳县| 乃东县| 民和| 乌审旗| 怀宁县| 会昌县| 攀枝花市| 武功县| 温宿县|