php兩種include載入檔案方式效率比較如下

2022-06-11 13:24:08 字數 1742 閱讀 6368

1)定義乙個字串變數,裡面儲存要載入的檔案列表。然後foreach載入。

$a = '/a.class.php;/util/b.class.php;/util/c.class.php';

$b = '/d.php;/e.class.php;/f.class.php;/g.class.php';

// 載入基本系統檔案

$kernel_require_files = explode(';', $a);//sys_require_lib_file_list);

foreach($kernel_require_files as $f){

require_once(sys_lib_path.'/system'.$f);

// 載入基本系統檔案

$kernel_require_files = explode(';', $b);//sys_base_file_list);

foreach($kernel_require_files as $f){

require_once(kernel_path.$f);

2)把所有的要載入的檔案都在乙個include檔案裡面載入,當前頁直接include這個include檔案。

include.php檔案內容

require_once('func.php');

require_once('langmanager.class.php');

require_once('_kernelautoloader.class.php');

require_once('lib/system/activator.class.php');

require_once('lib/system/util/cxml.class.php');

require_once('lib/system/util/cweb.class.php');

foreach

0.017754077911377

0.017686128616333

0.017347097396851

0.018272161483765

0.018272161483765

0.018401145935059

0.018187046051025

0.020787000656128

0.018001079559326

0.017963171005249

include_once('include.php');

0.025792121887207

0.024733066558838

0.025041103363037

0.024915933609009

0.024657011032104

0.024134159088135

0.025845050811768

0.024954080581665

0.024757146835327

0.02684497833252

另外,又嘗試了一下,直接在當前頁面載入所有檔案

0.022285938262939

0.024394035339355

0.023194074630737

0.023229122161865

0.024644136428833

0.023538112640381

0.024240016937256

0.025094032287598

0.023231029510498

0.02339506149292

PHP兩種include載入檔案方式效率比較

繼續完善 x計畫 的核心部分,核心嘛,就要載入必須的檔案,嘗試了兩種方法,發現效率是不同的,分享一下吧 先來說說兩種方式 1 定義乙個字串變數,裡面儲存要載入的檔案列表。然後foreach載入。a a.class.php util b.class.php util c.class.php b d.p...

PHP之include載入檔案

include include once require require once 都屬於語法結構,而非函式,在載入檔案錯誤與檔案重複上區別 include include 在php的include語法中,如果沒有給出路徑而只有檔名,則include有自己的尋找規則 在系統設定的include目錄中...

include的兩種區別

c 中經常會用到 include 和 include 它們到底有什麼區別呢?1.引入標準庫檔案 include filename.h 格式引用標準庫的標頭檔案。編譯器將從標準庫目錄開始搜尋。標準庫目錄是在開發環境中設定的庫檔案的路徑。如圖 2.也就是說編譯器會到這兩個路徑中找引用的檔案,如果找不到,...