???本文筆者是一個php初學者,下面是我一些筆記總結:
1.測試一個網站的負載量:
進入apache路徑下的bin目錄,比如我們要測試“同時處理50個請求并運行 1000 次 ab -c 50 -n 1000
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);
}
************ ($errno)<br>\n"; } else { while(!feof($fp)) { echo fgets($fp,128); } fclose($fp); } ?> :fsockopen("
錯誤:(0). 要想得到:http://www.nic.edu.cn/RS/ipstat/internalip/index.html 我該如何做? ************ *********** <?php echo "<script language=javascript>"; /* 確保重定向后,后續代碼不會被執行 */ <?php <?php 4.php 獲取當前絕對路徑 5.模擬HTTP 連線 5.print_r(HTTPrequest('get',?? 'www.w3.org',?? '/'));? 沒有二級域名 以/代替 6.PHP 模擬POST GET ('post','lnc.ep.duba.net','/***.aspx','ksn=*****));?? urlencoded\r\n";?? <?php 8.取當前路徑
?下面的代碼是正確的,返回了www.nic.edu.cn的首頁
<?php $fp = fsockopen("
但是問題是我想要得是:http://www.nic.edu.cn/RS/ipstat/internalip/index.html 但我將上面的代碼改成
建立server的socket連接跟HTTP沒有關系 不能在主機IP后面加路徑.
我覺得獲取遠程網頁 用fopen就可以了.
?$fp = fopen("?if(!$fp)
?{
??echo "N";
?}
?else
?{
??echo "Y";
?}
?>
3.php重定向
echo "document.location.href='xxxx.php";
echo </script>"; 響應者 3:<?php
header("location:
exit;
?>
header("location;http://www.****.com");
?>
echo "<meta http-equals=refresh content='0;url=http://www.***.com'>";
?>
<?php
??????? echo $_SERVER["DOCUMENT_ROOT"];
?>
jsp獲取當前絕對路徑
String path = request.getRealPath("");
<?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);??
? }??
? ?>??
<?php
?print_r(HTTPrequest
?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-
????$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.逐行讀取文件
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
??? while (!feof($handle)) {
??????? $buffer = fgets($handle, 4096);
??????? echo $buffer;
??? }
??? fclose($handle);
}
?>
echo?? dirname($_SERVER['SCRIPT_FILENAME']);??
:D:/kingsoft/KAN5/CONSOLE/trunk/src/V5WebConsole
echo $_SERVER['PHP_SELF'];
:/test.php