PHP擴充實現的簡單MVC架構

來源:互聯網
上載者:User
公司項目中WEB項目幾乎都是使用codeigniter架構,為了降低PHP的單次執行請求時間、減低伺服器處理回應時間,
同時提高每分鐘應答的總數,開發這個擴充的目的是將Router、Template、Config、Controller等架構提高的基礎通用功能由底層實現,
PHP指令碼僅處理商務邏輯,發揮各自的優勢。

考慮到項目遷移的成本,所以此擴充的MVC也是基於CI原型來設計的,同時也去除了很多不常用的功能。

支援版本:PHP5.3+

下面提供了兩張,1分鐘內針對相同網址並發數從10至100的請求測試結果。

資料對比:(測試載入器curl loader)類型      1分鐘總請求數     成功次數        失敗次數    平均回應時間   平均每秒請求數原CI架構    17706           15772           1844        137ms           267次擴充        57599           46654           10881       6ms             866次

原PHP Ci架構:

擴充MVC:

擴充實現的架構,響應速度提高了約10倍,請求總數提高了約3倍,失敗率提高了約8%。

使用案例: Nginx.conf配置單入口(與Ci一樣單入口一樣,沒有變動),例如:

   server {        listen 80;        server_name test.cn;        index index.php;        root /usr/local/wwwroot/test/public;          location / {                rewrite ^/$ /index.php last;                #一下是防止某些檔案夾被直接存取                rewrite ^/(?!index\.php|robots\.txt|images|js|css|styles|static)(.*)$ /index.php/$1 last;          }          location ~ \.php {                fastcgi_pass   127.0.0.1:9000;                fastcgi_index  index.php;                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;                include        fastcgi_params;          }    }

入口檔案index.php:

$application_folder = 'application';$dir_path = './';if (strpos(__FILE__, '\') !== false) {    $dir_path =  substr(__FILE__, 0, strrpos(__FILE__, '\')) . '/';} elseif (strpos(__FILE__, '/') !== false) {    $dir_path =  substr(__FILE__, 0, strrpos(__FILE__, '/')) . '/';}define('BASEPATH', str_replace("\", "/", realpath($dir_path.'../').'/'));define('APPPATH', realpath(BASEPATH.$application_folder).'/');$framework = new wk_framework();$framework->loadView();$framework->setTemplateDir(APPPATH.'../public/template/');$framework->setCompileDir(APPPATH.'../public/data/complie/');$framework->setApplicationPath(APPPATH);//此處release、test、development,會根據條件自動切換設定檔路徑//優先尋找/application/config/ENVIRONMENT/config,沒有在尋找/application/config/config$framework->setEnvironment('release');require_once(APPPATH.'core/WK_Controller.php');$framework->initialize();$framework->captureRouter();


安裝擴充方法參見: 進入
前往項目網址: 進入
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.