Home > Backend Development > PHP Tutorial > php pseudo-static

php pseudo-static

巴扎黑
Release: 2016-11-22 16:10:03
Original
1213 people have browsed it

Should we choose pseudo static or true static
1. There is no difference between using true static and false static for SEO
2. Using true static may cause hard disk damage and affect the forum performance
3. Using pseudo static will take up a certain amount of space Amount of CPU occupancy, heavy use will cause CPU overload
 4. The most important point is that we need to be static for SEO
 So:
 1. Using the true static method can be directly eliminated, because no matter how it is generated, it will affect the hard disk It's all very hurtful.
 2. Since the effect of true and false static is the same, we can choose pseudo static.
 3. However, extensive use of pseudo-static will cause CPU overload.
 4. So as long as we don’t use it in large quantities, it’s fine.
 5. Since static is only for SEO, we only need pseudo-static for SEO, and there is no need for users to use it.
 6. So we only need to use pseudo-static in the Archiver specially provided for SEO crawling.
 7. Thank you all for patiently reading my article.
8. If you have any questions or different opinions, please feel free to comment on pseudo-static and true static. There is an essential difference between true static and pseudo-static. Processing a pure HTML for browsing users and a PHP that calls multiple data have significantly less CPU usage than the former. I remember someone once said that the hard disk is frequently read and written when downloading HTML. He said this as if reading the database does not require reading and writing to the disk. What's more, there are a lot of cached scattered PHP that are also placed on the hard disk. Doesn't these reads require disk operations? ridiculous.
 The purpose can be achieved by reading a single html + image Flash and other attachments. Why bother reading the database, reading the php cache file, re-integrating the data output, and adding image Flash and other attachments? The CMS homepage does not require a lot of interaction, and the forum version should not be used here. On the contrary, what should be considered more is: beauty! compatible! Intuitive information! performance! And stability!

I am transferring a php pseudo-static implementation of four methods:

1 2 //Pseudo-static method one
3
4 // localhost/php100/test.php?id|1@action|2
5 $Php2Html_FileUrl = $_SERVER["REQUEST_URI"];
6 echo $Php2Html_FileUrl."
";// /php100/test.php?id|1@action|2
7 $Php2Html_UrlString = str_replace("? ","",str_replace("/", "", strrchr(strrchr($Php2Html_FileUrl, "/"),"?")));
8 echo $Php2Html_UrlString."
";// id| 1@action|2
9 $Php2Html_UrlQueryStrList = explode("@", $Php2Html_UrlString);
10 print_r($Php2Html_UrlQueryStrList);// Array ( [0] => id|1 [1] => action|2 )
11 echo "
";
12 foreach($Php2Html_UrlQueryStrList as $Php2Html_UrlQueryStr)
13 {
14 $Php2Html_TmpArray = explode("|", $Php2Html_UrlQueryStr);
15 print_r( $Php2Html_TmpArray);//Array ( [0] => id [1] => 1 ) ; Array ( [0] => action [1] => 2 )
16 echo "
";
17 $_GET[$ Php2Html_TmpArray[0]] = $Php2Html_TmpArray[1];
18 }
19 //echo 'Fake static: $_GET variable
';
20 print_r($_GET); // Array ( [id| 1@action|2] => [id] => 1 [action] => 2 )
21 echo "
";
22 echo "


";
23 echo $_GET[ id]."
";// 1
24 echo $_GET[action];// 2
25 ?>
26

1 2 //Pseudo-static method two
3
4 // localhost/php100/test.php/1/2
5 $filename = basename($_SERVER['SCRIPT_NAME']);
6 echo $_SERVER['SCRIPT_NAME']."
";// /php100/test.php
7 echo $filename."
";// test.php
8
9 if(strtolower($filename)=='test.php'){
10 if(!empty ($_GET[id])){
11 $id=intval($_GET[id]);
12 echo $id."
";
13 $action=intval($_GET[action]);
14 echo $action."
";
15 }else{
16 $nav=$_SERVER['REQUEST_URI'];
17 echo "1:".$nav."
";/ / /php100/test.php/1/2
18 $script=$_SERVER['SCRIPT_NAME'];
19   echo "2:".$script."
";// /php100/test.php 
20    $nav=ereg_replace("^$script","",urldecode($nav)); 
21   echo $nav."
"; // /1/2 
22    $vars=explode("/",$nav); 
23   print_r($vars);// Array ( [0] => [1] => 1 [2] => 2 ) 
24    echo "
"; 
25   $id=intval($vars[1]); 
26   $action=intval($vars[2]); 
27  } 
28  echo $id.'&'.$action; 
29 } 
30  ?> 
31  

1 2 //伪静态方法三 


5 function mod_rewrite(){ 
6 global $_GET; 
7 $nav=$_SERVER["REQUEST_URI"]; 
8 echo $nav."
"; 
9 $script_name=$_SERVER["SCRIPT_NAME"]; 
10 echo $script_name."
"; 
11 $nav=substr(ereg_replace("^$script_name","",urldecode($nav)),1); 
12 echo $nav."
"; 
13 $nav=preg_replace("/^.ht(m){1}(l){0,1}$/","",$nav);//这句是去掉尾部的.html或.htm 
14 echo $nav."
"; 
15 $vars = explode("/",$nav); 
16 print_r($vars); 
17 echo "
"; 
18 for($i=0;$i19 $_GET["$vars[$i]"]=$vars[$i+1]; 
20 } 
21 return $_GET; 
22 } 
23 mod_rewrite(); 
24 $year=$_GET["year"];//结果为'2006' 
25 echo $year."
"; 
26 $action=$_GET["action"];//结果为'_add' 
27 echo $action; 
28 ?> 
29 

1 2 //伪静态方法四 

4 //利用server变量 取得PATH_INFO信息 该例中为 /1,100,8630.html   也就是执行脚本名后面的部分 
5 if(@$path_info =$_SERVER["PATH_INFO"]){ 
6 //正则匹配一下参数 
7 if(preg_match("//(d+),(d+),(d+).html/si",$path_info,$arr_path)){ 
8 $gid     =intval($arr_path[1]); //取得值 1 
9 $sid     =intval($arr_path[2]);   //取得值100 
10 $softid   =intval($arr_path[3]);   //取得值8630 
11 }else die("Path:Error!"); 
12 //相当于soft.php?gid=1&sid=100&softid=8630 
13 }else die('Path:Nothing!'); 
14 ?> 

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template