PHP各種導入ファイル関数の実行効率include require fpassthru readfile

4720 ワード

http://www.ccvita.com/163.html
どのようにphpの実行効率を向上させるかを研究しています。includeが多すぎるファイルはphpの実行時間を高めることができると直感しています。しかし、いくつかのファイルは確かにまた導入する必要があります。phpの各種導入ファイル関数の実行効率を試してみます。データをphpファイルにキャッシュするのは一番いい方法ではないです。小データ量の場合はテキストキャッシュの読み取り可能性が一番いいです。
また、実はいくつかの場合、やはりgoogleがいいです。http://www.raditha.com/wiki/Readfile_vs_include
It is not off tens that you can write a PHP script that does not need to include the contens of different files s s s parts of it's output.If these includen to be phripts themselves the mselves have Hove the chorequares.Hotent。usualy.template component.With static includes you have many more options available.aerwear We will anlyse some of these functions to find out which one is most suitable with files with static content funce
Function
Brief Description
string fileゲットするcontensts(string filename[,int use ludeuplath])
Reads entire file into a string
int fpassthru(reource handle)
Output all remaning data on a file pointer
string fgets(reource handle[,int length])
Gets line from file pointer
array file(string filename[,int useuincludeuplath])
Reads entire file into an array
require(string filename)
include(string filename)
require_once(string filename)
include_once(string filename)
includies and evaluates the specifile.
int readfile(string filename[,int useuincludeuplath])
Outputs a file
We will now atempt to‘include’the contens of a 1 megabyte file into the out put produced by our php script.How You geners files of specifile sizes is described elsewhere.The execution ption
We compnsate for file caching and background process es by executing each script 4 times and taring the average(mean)of the reult number 2-4.The first reult is always rejeced.Anrery ult thapt appers.the apearts
Function
Sample Usage
Time(s)
メモリ(b)
file_ゲットするcontensts
echo file_ゲットするcontensts($filename);
0.00564
10786
fpassthru
fpassthru($fp)
0.00184
20032
fgets
$fp = fopen($filename,"rb");
while(!feof($fp))
{
echo fgets($fp);
}
0.07190
30768
file
echo join(",file($filename);
0.06464
215624
requiremonce
requireyice($filename);
0.08065
2067696
include
include($filename);
0.08202
2067696
readfile
readfile($filename);
0.00191
19208
What’s s ovious from therereresusuststs s s s s s s s s s s s s s s s s s s s s s s s s s s s sisisisisisisisisisisisisisisisisists s s s s s s s s s s s s s s s s s s s s s s s s passththththththththththandandandandandand rerererereadreadfififififififififirerereadrererereadrerereadfirerererererererererererereadfilelee e e e e e eeeeeeeeeeeeeeeeeequalalalalalalalalalalalalalalalalt 100000 times to make significantsaving.On memory consumpation readfile seems to have use up around 1 kb less than passthu.A kilo byte is a drop in the ocean for moden web servers with hndreds of megabytes of memory.
The only conclusion that can be drawn from these studies is that fpassu u and readfile are equally good wish to include static content as part of the script's out.
Before you rush off to change all your inclues and requires into readfiles or fpassthrus let’s run the same test with a smaler.32 Kb is a more alistic size forn includ file.
Function
Time(s)
メモリ(b)
32 Kb File
1 Mb File
32 Kb File
1 Mb File
filegotch.
0.00152
0.00564
52480
10786
fpassthru
0.00117
0.00184
20016
20032
fgets
0.00195
0.07190
30760
30768
file
0.00157
0.06464
87344
215624
requiremonce
0.00225
0.08065
67992
2067696
include
0.00222
0.08202
67928
2067624
readfile
0.00117
0.00191
19192
19208
readfile and fpassthru have once again tied for first place.This new set of reults just confirms the fact that speed and scalability cour design and not from your code.The difference bets betwence the bets and
The most significant feature of these rerererestststststrerereststststststrererererereath th th fpassu u and readfile scalalalalalalalalalalalalalalalalalalaaze.In other wods,memomomomoryconsution and eeeeeeeeeeeeeeeeeeeeeeeeeeemenmentstststststsininininininininininininininininininininininincrcreaeatstsnininininifistststininininininininininininininininininininininininininininininclude.