日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

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

發布時間:2024/9/20 php 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP框架 Phalcon 1.0.0 beta发布,实测性能强劲 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們宣布今天(時差問題,應該是昨天了)發布Phalcon 1.0.0 beta版本,發布此版本,主要是從社區得到測試反饋加以改進。此版本引入了一些比較重要的特性:

多級緩存:

這個新功能是緩存組件的一部分,允許開發人員來實現一個多級緩存。這個新功能非常有用,因為你可以保存相同的數據在多個后端緩存組件中,并可配置不同的生命周期,讀取緩存從最快的適配器到最慢的一個,直到數據都已經過期:

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模板引擎改進
此版本引入的一些Volt改進特性:

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>

垂直/水平分片的改進
現在,你可以定義不同的數據庫連接,使之一個只用于讀操作,另一個只用于寫操作。對于RDBMS中使用主從方式的應用場景非常有用:

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

在大中型項目中,在數據庫設計的時候,考慮到數據庫最大承受數據量,通常會把數據庫或者數據表水平切分,以降低單個庫,單個表的壓力。
因此,水平切片意味著讀取數據將根據條件進行數據查詢:

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}

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

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

動態更新
此功能允許ORM在創建SQL UPDATE語句時,只改變有改變的字段,而不是整個表的所有字段。在某些情況下,這可以提高性能,減少應用程序與數據庫服務器之間的傳輸數據量:

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

驗證
Phalcon\Validation 是基于ORM,ODM驗證系統實現的一個獨立的驗證組件,該組件可以在model及collection之外實現驗證規則:

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還包括其他一些小改動,bug修復及穩定性方面的改進。你可以在此看到完整的更新日志

?

幫助測試
可以從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 進行交流。如果你發現了任何BUG,請在Github上創建issue.

中文文檔: http://phalcon.5iunix.net

總結

以上是生活随笔為你收集整理的PHP框架 Phalcon 1.0.0 beta发布,实测性能强劲的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。