PHP static

  PHP site development process, because search engines have some differences on collection of PHP and html pages will include, in order to promote the needs of your site or SEO, you need to be certain static site. Static pages is not no animation and other elements, but to the web pages of html code in your page, do not need to go to perform voice servicer side PHP scripts, etc., we are able to have direct access to, this is the static pages.

       One way is to rewrite the security addresses, can be altered by a URL PATHINFO model it, make it look more like a static page, so there is a greater chance of being crawled and indexed by search engines, only a search engine more friendly, pseudo-static

       The second is the site before a user can access the site will be static, static pages generated by a certain program when the user to access the page, because access to static pages, therefore, access speed than the dynamic page access a very faster times, the performance of the foreground page loading speed is faster, and in the background is to reduce the link to the database, reducing the pressure on the database, more accounted for only drawback is relatively hard, relatively inexpensive hard drive more.

       Pure static, that is, production HTML file, we need to enable PHP caching mechanism that comes with that ob_start to open the cache, and can not have any output before ob_start, otherwise fail, then we ob_get_content function to get the cache content, the function returns a string, and the third function is ob_end_clean, which is used to empty the contents of the cache and Close to return true if successful, otherwise returns false.

? <PHP 
// open the cache
ob_start ();
// The first step in connecting to the database
$ conn = mysqli_connect ( "localhost", "root", "", "BBS");
// set the second step corresponding to the character encoding
$ = Setting 'SET UTF8 names';
the mysqli_query (Conn $, $ Setting);
query // step
$ SQL = 'the SELECT * the FROM User';
$ Result = the mysqli_query (Conn $, $ SQL);
// fourth step query results into an array
$ rows = mysqli_num_rows ($ result);
$ SQLData = array ();
for ($ I = 0; $ I <$ rows; $ I ++) {
$ SQLData [] = mysqli_fetch_assoc ( the Result $);
}
// then print the information
var_dump ($ the SQLData);
// get html file generated, without having to access the database on the next visit to the
$ msg = ob_get_contents ();
ob_end_clean ();
// output content into a html file
$f = fopen("static.html","w");
fwrite($f,$msg);
echo "静态化成功";

Guess you like

Origin www.cnblogs.com/Mr-Echo/p/12148317.html