国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 談PHP生成靜態(tài)頁面

談PHP生成靜態(tài)頁面

Jun 08, 2016 pm 05:33 PM
flush length string void

<script>ec(2);</script>

一、引 言

在速度上,靜態(tài)頁面要比動態(tài)頁面的比方php快很多,這是毫無疑問的,但是由于靜態(tài)頁面的靈活性較差,假如不借助數(shù)據(jù)庫或其他的設(shè)備保存相關(guān)信息的話,整體的治理上比較繁瑣,比方修改編輯.比方閱讀權(quán)限限制等,但是,對應(yīng)一些我們經(jīng)常頻頻使用的文件,比方說,開發(fā)的新聞發(fā)布系統(tǒng),我們不希望很多用戶都讀取數(shù)據(jù)庫才顯示結(jié)果,這樣一方面消耗了服務(wù)器的資源,另一方面占去了瀏覽者大量可貴的響應(yīng)時間,所有,有了"靜態(tài)頁面話"的做法,當(dāng)前很多網(wǎng)站都采用這種技術(shù),一般都是由治理后臺控制,或者生成html直接顯示,或者xhtml用css控制顯示,或者生成xml用xslt顯示,這些技術(shù)都不是難的,在這里我就淺顯的說說生成html的方法.

二、預(yù)備知識

模板技術(shù):

緩存技術(shù):

有些信息比方經(jīng)常不變的,但是還是能變的信息放在緩存中以加快顯示速度,這是很有價值的,所謂的緩存,通俗的理解就是一些保存在服務(wù)器端的共用信息.它是于服務(wù)器同生死的,我們在保存緩存的時候可以指定下次更新的時間的判定,比方要在5分鐘更新一次,可以記錄上次更新的時間,和當(dāng)前時間比較,假如大于 5 分鐘 ,讀取數(shù)據(jù)庫,更新?lián)Q成,否則直接讀取緩存數(shù)據(jù),當(dāng)然,緩存需要客戶端用戶激活的,只需一次.

ob_start()函數(shù):打開輸出緩沖區(qū).
函數(shù)格式 void ob_start(void)
說明:當(dāng)緩沖區(qū)激活時,所有來自PHP程序的非文件頭信息均不會發(fā)送,而是保存在內(nèi)部緩沖區(qū)。為了輸出緩沖區(qū)的內(nèi)容,可以使用ob_end_flush()或flush()輸出緩沖區(qū)的內(nèi)容。

Flush:刷新緩沖區(qū)的內(nèi)容,輸出。
函數(shù)格式:flush()
說明:這個函數(shù)經(jīng)常使用,效率很高。

ob_get_contents :返回內(nèi)部緩沖區(qū)的內(nèi)容。
函數(shù)格式:string ob_get_contents(void)
說明:這個函數(shù)會返回當(dāng)前緩沖區(qū)中的內(nèi)容,假如輸出緩沖區(qū)沒有激活,則返回 FALSE.

ob_get_length:返回內(nèi)部緩沖區(qū)的長度。
函數(shù)格式:int ob_get_length(void)
說明:這個函數(shù)會返回當(dāng)前緩沖區(qū)中的長度;和ob_get_contents一樣,假如輸出緩沖區(qū)沒有激活,則返回 FALSE.

ob_end_clean:刪除內(nèi)部緩沖區(qū)的內(nèi)容,并且關(guān)閉內(nèi)部緩沖區(qū)
函數(shù)格式:void ob_end_clean(void)
說明:這個函數(shù)不會輸出內(nèi)部緩沖區(qū)的內(nèi)容而是把它刪除

ob_end_flush:發(fā)送內(nèi)部緩沖區(qū)的內(nèi)容到瀏覽器,并且關(guān)閉輸出緩沖區(qū)
函數(shù)格式:void ob_end_flush(void)
說明:這個函數(shù)發(fā)送輸出緩沖區(qū)的內(nèi)容(假如有的話)

ob_implicit_flush:打開或關(guān)閉絕對刷新
函數(shù)格式:void ob_implicit_flush ([int flag])
說明:默認為關(guān)閉緩沖區(qū),打開絕對輸出后,每個腳本輸出都直接發(fā)送到瀏覽器,不再需要調(diào)用 flush()

文件寫入:

int fwrite ( resource handle, string string [, int length] )
fwrite() 把 string 的內(nèi)容寫入 文件指針 handle 處。 假如指定了 length,當(dāng)寫入了 length 個字節(jié)或者寫完了 string 以后,寫入就會停止,視乎先碰到哪種情況。
fwrite() 返回寫入的字符數(shù),出現(xiàn)錯誤時則返回 FALSE 。
相關(guān)參考官方網(wǎng)站: 文件參考

三、解決方案

思路:開啟 ob_start緩沖,當(dāng)已經(jīng)調(diào)出數(shù)據(jù)的時候獲取 ob_get_contents,然后生成靜態(tài)頁,ob_end_clean清除緩沖.ok,就這么來,來看一個例子(php mysql的結(jié)合):

創(chuàng)建數(shù)據(jù)庫:

CREATE TABLE `bihtml` (
`id` int(11) NOT NULL auto_increment,
`szdtitle` varchar(16) NOT NULL,
`szdcontent` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does void mean in java What does void mean in java Mar 01, 2023 pm 07:19 PM

In Java, void means "empty", that is, "returns nothing". When the method is declared, it means that the method has no return value. ?void corresponds to a wrapper class "java.lang.Void". The Void class is modified with final and is a non-instantiable placeholder class used to save a reference to the Class object that represents the Java keyword void.

Convert basic data types to strings using Java's String.valueOf() function Convert basic data types to strings using Java's String.valueOf() function Jul 24, 2023 pm 07:55 PM

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

How to convert char array to string How to convert char array to string Jun 09, 2023 am 10:04 AM

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

Use Java's String.replace() function to replace characters (strings) in a string Use Java's String.replace() function to replace characters (strings) in a string Jul 25, 2023 pm 05:16 PM

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

Use java's String.length() function to get the length of a string Use java's String.length() function to get the length of a string Jul 25, 2023 am 09:09 AM

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

The function of void keyword in C language The function of void keyword in C language Feb 19, 2024 pm 11:33 PM

void in C is a special keyword used to represent an empty type, which means data without a specific type. In C language, void is usually used in the following three aspects. The function return type is void. In C language, functions can have different return types, such as int, float, char, etc. However, if the function does not return any value, the return type can be set to void. This means that after the function is executed, it does not return a specific value. For example: voidhelloWorld()

What is the significance of using void type return value in PHP? What is the significance of using void type return value in PHP? Apr 10, 2024 pm 09:21 PM

In PHP, the void type return value means that the function does not return any value, and is usually used for operations such as updating records that do not require a return value. Use the void keyword when declaring a void function; when calling a void function, the result must not be assigned to a variable. Practical case: void type return value can be used to update database records without returning any information.

How to understand and solve 'javascript:void(O)' problems How to understand and solve 'javascript:void(O)' problems Feb 19, 2024 pm 05:35 PM

What does javascript:void(0) mean? What are the solutions to this problem? When we browse the web, sometimes we encounter some links that do not respond after clicking, but are displayed as "javascript:void(0)" in the browser's address bar. This question may confuse some web visitors as they don't know what the error message, which literally looks like JavaScript code, means. So, let's unpack this together

See all articles