日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

PHP框架 Phalcon 1.0.0 beta发布,实测性能强劲

發(fā)布時(shí)間:2024/9/20 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)過期:

01<?php
02$ultraFastFrontend = new Phalcon\Cache\Frontend\Data(array(
03????"lifetime" => 3600
04));
05?
06$fastFrontend = new Phalcon\Cache\Frontend\Data(array(
07????"lifetime" => 86400
08));
09?
10$slowFrontend = new Phalcon\Cache\Frontend\Data(array(
11????"lifetime" => 604800
12));
13?
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',
18??)),
19??new Phalcon\Cache\Backend\Memcache($fastFrontend, array(
20????"prefix" => 'cache',
21????"host" => "localhost",
22????"port" => "11211"
23??)),
24??new Phalcon\Cache\Backend\File($slowFrontend, array(
25????"prefix" => 'cache',
26????"cacheDir" => "../app/cache/"
27??))
28));
29?
30//Save, saves in every backend
31$cache->save('my-key', $data);


Volt模板引擎改進(jìn)
此版本引入的一些Volt改進(jìn)特性:

01{# Ternary operator #}
02{{ total > 0 ? total|format('%0.2f') : '0.0' }}
03?
04{# For-Else clause #}
05{% for robot in robots %}
06????{{ robot.name }}
07{% else %}
08????There are no robots
09{% endfor %}
10?
11{# Loop-Context #}
12<table>
13{% for robot in robots %}
14????{% if loop.first %}
15????????<thead>
16????????????<tr>
17????????????????<th>Position</th>
18????????????????<th>Id</th>
19????????????????<th>Name</th>
20????????????</tr>
21????????</thead>ae
22????????<tbody>
23????{% endif %}
24????<tr>
25????????<th>{{ loop.index }}</th>
26????????<th>{{ robot.id }}</th>
27????????<th>{{ robot.name }}</th>
28????</tr>
29????{% if loop.last %}
30????????<tbody>
31????{% endif %}
32{% endfor %}
33</table>
34?
35{# Space control delimiters #}
36<ul>
37????{%- for robot in robots -%}
38????<li>? {{- robot.name -}}</li>
39????{%- endfor %}
40</ul>

垂直/水平分片的改進(jìn)
現(xiàn)在,你可以定義不同的數(shù)據(jù)庫連接,使之一個(gè)只用于讀操作,另一個(gè)只用于寫操作。對于RDBMS中使用主從方式的應(yīng)用場景非常有用:

1class Robots extends Phalcon\Mvc\Model
2{
3????public function initialize()
4????{
5????????$this->setReadConnectionService('dbSlave');
6????????$this->setWriteConnectionService('dbMaster');
7????}
8}

在大中型項(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ù)查詢:

01class Robots extends Phalcon\Mvc\Model
02{
03????public function selectReadConnection($intermediate, $bindParams, $bindTypes)
04????{
05????????//Check if there is a 'where' clause in the select
06????????if (isset($intermediate['where'])) {
07?
08????????????$conditions = $intermediate['where'];
09?
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');
15????????????????}
16????????????????if ($id > 10000) {
17????????????????????return $this->getDI()->get('dbShard2');
18????????????????}
19????????????}
20????????}
21?
22????????//Use a default shard
23????????return $this->getDI()->get('dbShard0');
24????}
25?
26}

記錄快照
有了這項(xiàng)新功能,指定的Models可以設(shè)定為查詢時(shí)保持記錄的快照。你可以使用此功能來實(shí)現(xiàn)審計(jì)或只是為了知道哪些字段被更改過:

1class Robots extends Phalcon\Mvc\Model
2{
3????public function initalize()
4????{
5????????$this->keepSnapshots(true);
6????}
7}

你可以通過以下方式檢測哪些字段被更改過:

1$robot = new Robots();
2$robot->name = 'Other name';
3var_dump($robot->getChangedFields()); // ['name']
4var_dump($robot->hasChanged('name')); // true
5var_dump($robot->hasChanged('type')); // false

動(dòng)態(tài)更新
此功能允許ORM在創(chuàng)建SQL UPDATE語句時(shí),只改變有改變的字段,而不是整個(gè)表的所有字段。在某些情況下,這可以提高性能,減少應(yīng)用程序與數(shù)據(jù)庫服務(wù)器之間的傳輸數(shù)據(jù)量:

1class Robots extends Phalcon\Mvc\Model
2{
3????public function initalize()
4????{
5????????$this->useDynamicUpdate(true);
6????}
7}

驗(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();
02?
03$validation
04????->add('name', new PresenceOf(array(
05????????'message' => 'The name is required'
06????)))
07????->add('name', new StringLength(array(
08????????'min' => 5,
09????????'minimumMessage' => 'The name is too short'
10????)))
11????->add('email', new PresenceOf(array(
12????????'message' => 'The email is required'
13????)))
14????->add('email', new Email(array(
15????????'message' => 'The email is not valid'
16????)))
17????->add('login', new PresenceOf(array(
18????????'message' => 'The login is required'
19????)));
20?
21$messages = $validation->validate($_POST);
22if (count($messages)) {
23????foreach ($messages as $message) {
24????????echo $message;
25????}
26}

版本 1.0.0還包括其他一些小改動(dòng),bug修復(fù)及穩(wěn)定性方面的改進(jìn)。你可以在此看到完整的更新日志

?

幫助測試
可以從1.0.0分支中安裝此版本:

1git clone http://github.com/phalcon/cphalcon
2cd build
3git checkout 1.0.0
4sudo ./install

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ò),歡迎將生活随笔推薦給好友。