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

來源:互聯網
上載者:User

標籤:tin   foreach   setting   base   XML   util   .class   lan   man   

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(‘ApplicationSettingManager.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這些多餘的運算~凡事要論證,不能憑空想象,所以,我驗證了一下。以下是用兩種方法隨機10次載入所消耗的時間:

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負載檔案方式效率比較如下

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.