生活随笔
收集整理的這篇文章主要介紹了
PHP框架 Phalcon 1.0.0 beta发布,实测性能强劲
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
我們宣布今天(時(shí)差問題,應(yīng)該是昨天了)發(fā)布Phalcon 1.0.0 beta版本,發(fā)布此版本,主要是從社區(qū)得到測試反饋加以改進(jìn)。此版本引入了一些比較重要的特性:
多級(jí)緩存:
這個(gè)新功能是緩存組件的一部分,允許開發(fā)人員來實(shí)現(xiàn)一個(gè)多級(jí)緩存。這個(gè)新功能非常有用,因?yàn)槟憧梢员4嫦嗤臄?shù)據(jù)在多個(gè)后端緩存組件中,并可配置不同的生命周期,讀取緩存從最快的適配器到最慢的一個(gè),直到數(shù)據(jù)都已經(jīng)過期:
| 02 | $ultraFastFrontend = new Phalcon\Cache\Frontend\Data(array( |
| 06 | $fastFrontend = new Phalcon\Cache\Frontend\Data(array( |
| 07 | ????"lifetime" => 86400 |
| 10 | $slowFrontend = new Phalcon\Cache\Frontend\Data(array( |
| 11 | ????"lifetime" => 604800 |
| 14 | //Backends are registered from the fastest to the slower |
| 15 | $cache = new \Phalcon\Cache\Multiple(array( |
| 16 | ????new Phalcon\Cache\Backend\Apc($ultraFastFrontend, array( |
| 17 | ????"prefix" => 'cache', |
| 19 | ??new Phalcon\Cache\Backend\Memcache($fastFrontend, array( |
| 20 | ????"prefix" => 'cache', |
| 21 | ????"host" => "localhost", |
| 24 | ??new Phalcon\Cache\Backend\File($slowFrontend, array( |
| 25 | ????"prefix" => 'cache', |
| 26 | ????"cacheDir" => "../app/cache/" |
| 30 | //Save, saves in every backend |
| 31 | $cache->save('my-key', $data); |
Volt模板引擎改進(jìn)
此版本引入的一些Volt改進(jìn)特性:
| 02 | {{ total > 0 ? total|format('%0.2f') : '0.0' }} |
| 05 | {% for robot in robots %} |
| 08 | ????There are no robots |
| 13 | {% for robot in robots %} |
| 14 | ????{% if loop.first %} |
| 17 | ????????????????<th>Position</th> |
| 18 | ????????????????<th>Id</th> |
| 19 | ????????????????<th>Name</th> |
| 25 | ????????<th>{{ loop.index }}</th> |
| 26 | ????????<th>{{ robot.id }}</th> |
| 27 | ????????<th>{{ robot.name }}</th> |
| 35 | {# Space control delimiters #} |
| 37 | ????{%- for robot in robots -%} |
| 38 | ????<li>? {{- robot.name -}}</li> |
垂直/水平分片的改進(jìn)
現(xiàn)在,你可以定義不同的數(shù)據(jù)庫連接,使之一個(gè)只用于讀操作,另一個(gè)只用于寫操作。對于RDBMS中使用主從方式的應(yīng)用場景非常有用:
| 1 | class Robots extends Phalcon\Mvc\Model |
| 3 | ????public function initialize() |
| 5 | ????????$this->setReadConnectionService('dbSlave'); |
| 6 | ????????$this->setWriteConnectionService('dbMaster'); |
在大中型項(xiàng)目中,在數(shù)據(jù)庫設(shè)計(jì)的時(shí)候,考慮到數(shù)據(jù)庫最大承受數(shù)據(jù)量,通常會(huì)把數(shù)據(jù)庫或者數(shù)據(jù)表水平切分,以降低單個(gè)庫,單個(gè)表的壓力。
因此,水平切片意味著讀取數(shù)據(jù)將根據(jù)條件進(jìn)行數(shù)據(jù)查詢:
| 01 | class Robots extends Phalcon\Mvc\Model |
| 03 | ????public function selectReadConnection($intermediate, $bindParams, $bindTypes) |
| 05 | ????????//Check if there is a 'where' clause in the select |
| 06 | ????????if (isset($intermediate['where'])) { |
| 08 | ????????????$conditions = $intermediate['where']; |
| 10 | ????????????//Choose the possible shard according to the conditions |
| 11 | ????????????if ($conditions['left']['name'] == 'id') { |
| 12 | ????????????????$id = $conditions['right']['value']; |
| 13 | ????????????????if ($id > 0 && $id < 10000) { |
| 14 | ????????????????????return $this->getDI()->get('dbShard1'); |
| 16 | ????????????????if ($id > 10000) { |
| 17 | ????????????????????return $this->getDI()->get('dbShard2'); |
| 22 | ????????//Use a default shard |
| 23 | ????????return $this->getDI()->get('dbShard0'); |
記錄快照
有了這項(xiàng)新功能,指定的Models可以設(shè)定為查詢時(shí)保持記錄的快照。你可以使用此功能來實(shí)現(xiàn)審計(jì)或只是為了知道哪些字段被更改過:
| 1 | class Robots extends Phalcon\Mvc\Model |
| 3 | ????public function initalize() |
| 5 | ????????$this->keepSnapshots(true); |
你可以通過以下方式檢測哪些字段被更改過:
| 2 | $robot->name = 'Other name'; |
| 3 | var_dump($robot->getChangedFields()); // ['name'] |
| 4 | var_dump($robot->hasChanged('name')); // true |
| 5 | var_dump($robot->hasChanged('type')); // false |
動(dòng)態(tài)更新
此功能允許ORM在創(chuàng)建SQL UPDATE語句時(shí),只改變有改變的字段,而不是整個(gè)表的所有字段。在某些情況下,這可以提高性能,減少應(yīng)用程序與數(shù)據(jù)庫服務(wù)器之間的傳輸數(shù)據(jù)量:
| 1 | class Robots extends Phalcon\Mvc\Model |
| 3 | ????public function initalize() |
| 5 | ????????$this->useDynamicUpdate(true); |
驗(yàn)證
Phalcon\Validation 是基于ORM,ODM驗(yàn)證系統(tǒng)實(shí)現(xiàn)的一個(gè)獨(dú)立的驗(yàn)證組件,該組件可以在model及collection之外實(shí)現(xiàn)驗(yàn)證規(guī)則:
| 01 | $validation = new Phalcon\Validation(); |
| 04 | ????->add('name', new PresenceOf(array( |
| 05 | ????????'message' => 'The name is required' |
| 07 | ????->add('name', new StringLength(array( |
| 09 | ????????'minimumMessage' => 'The name is too short' |
| 11 | ????->add('email', new PresenceOf(array( |
| 12 | ????????'message' => 'The email is required' |
| 14 | ????->add('email', new Email(array( |
| 15 | ????????'message' => 'The email is not valid' |
| 17 | ????->add('login', new PresenceOf(array( |
| 18 | ????????'message' => 'The login is required' |
| 21 | $messages = $validation->validate($_POST); |
| 22 | if (count($messages)) { |
| 23 | ????foreach ($messages as $message) { |
版本 1.0.0還包括其他一些小改動(dòng),bug修復(fù)及穩(wěn)定性方面的改進(jìn)。你可以在此看到完整的更新日志
?
幫助測試
可以從1.0.0分支中安裝此版本:
| 1 | git clone http://github.com/phalcon/cphalcon |
Windows用戶可以直接從下載頁面下載DLL文件。
我們歡迎您提供寶貴的意見與建議,可以通過 Phosphorum, Stack Overflow or Google Group 進(jìn)行交流。如果你發(fā)現(xiàn)了任何BUG,請?jiān)贕ithub上創(chuàng)建issue.
中文文檔: http://phalcon.5iunix.net
總結(jié)
以上是生活随笔為你收集整理的PHP框架 Phalcon 1.0.0 beta发布,实测性能强劲的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。