![Page 1: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/1.jpg)
Phalcon The Fastest PHP Framework
Rack Lin 阿土伯 @phpcon8w2013
![Page 2: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/2.jpg)
about:me
! 目前為 ViViPOS Co., Ltd 技術總監 ! 利用 javascript 寫 〞收銀機〞(傳統產業,全新感受)
! PHP / Javascript / Java Programmer (目前移情於 Scala )
! hNps://twiNer.com/racklin
! hNps://www.facebook.com/racklin1002
! hNp://racklin.blogspot.tw/ (生小孩後就變癈墟)
![Page 3: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/3.jpg)
2012 cphalcon contributors
![Page 4: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/4.jpg)
2013 cphalcon contributors
![Page 5: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/5.jpg)
學如逆⽔水⾏行⾈舟、不進則退
在 Open Source 更是如此
![Page 6: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/6.jpg)
Phalcon Framework Phalcon Kernel
Zephir
![Page 7: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/7.jpg)
Phalcon Dev Box
! Virtual Machine for PhalconPHP Development
! hNps://github.com/racklin/phalcon-‐dev-‐box
! Vagrant / VirtualBox
![Page 8: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/8.jpg)
Phalcon Benefits
! The Fastest
! Few Memory Usage
! Cross-‐PlaZorm
! Highly Decoupled ! Full-‐stack Framework
C 實作
![Page 9: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/9.jpg)
C 有多快
! Fibonacci 40 (費式數列) hNp://bit.ly/Pk8HkJ
Language Times
C with –O2 0m0.202s
java 0m1.305s
scala 0m1.808s
nodejs 0m2.872s
Ruby (1.9.x) 0m37.404s
Php (5.4) 1m17.728s
Python (2.7.2) 1m17.979s
Ruby (1.8.x) 3m35.135s
Php (5.3) 6m17.192s
![Page 10: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/10.jpg)
Fibonacci 40
0
100
200
300
400
500
c with -‐O2
java scala nodejs ruby 1.9.2
php 5.4 ruby 1.8.x
php 5.3
![Page 11: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/11.jpg)
所以結論…
為了快!專案要用 c / c++ 來寫 web
![Page 12: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/12.jpg)
Raphters ! A web framework for C
![Page 13: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/13.jpg)
除了慣C哥
大部份人打完招呼 Hello World!
不知道要做什麼…..
![Page 14: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/14.jpg)
Fibonacci as php extension
![Page 15: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/15.jpg)
Fibonacci as php extension
0m0.79s 馬上變成第二名
![Page 16: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/16.jpg)
Fibonacci 圖表
0 50
100 150 200 250 300 350 400 450
c with -‐O2 java scala nodejs ruby 1.9.2 php 5.4 ruby 1.8.x php 5.3 php ext
![Page 17: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/17.jpg)
速度只要出問題, C 都能搞定
![Page 18: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/18.jpg)
平衡
A PHP web framework
delivered as a C extension
![Page 19: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/19.jpg)
Frameworks benchmark
![Page 20: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/20.jpg)
Frameworks benchmark
![Page 21: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/21.jpg)
速度不是問題?
![Page 22: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/22.jpg)
![Page 23: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/23.jpg)
![Page 24: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/24.jpg)
![Page 25: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/25.jpg)
Raspberry Pi
![Page 26: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/26.jpg)
Raspberry Pi
! OS: Raspbian (Debian 7)
! Web Server: Nginx 1.2.1
! PHP 5.4.4 (FPM)
! CPU: ARMv6 700 MHz
! RAM: 512MB (480MB)
! Disk: 4GB Class 6 SDHC
hNps://gist.github.com/hdogan/5466569
![Page 27: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/27.jpg)
Frameworks benchmark Pi
2.89 3.96 5.4
67.38
0
10
20
30
40
50
60
70
80
Laravel Yii CodeIgniter Phalcon
Requests per Second
![Page 28: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/28.jpg)
Frameworks benchmark Pi
345.58
252.61
185.24
14.84 0
50
100
150
200
250
300
350
400
Laravel Yii CodeIgniter Phalcon
Memory Usage
![Page 29: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/29.jpg)
Highly Decoupled
! Ex. Validamon
![Page 30: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/30.jpg)
EVERYTHING YOU NEED
! Single or Mulm Module MVC Applicamons
! Sinatra / Slim / expressjs like Micro Applicamons.
! Dependency Injecmon/Container
! Universal Auto-‐Loader
! Events Management
! ORM – MySQL / PostgreSQL (#schema)/ SQLite
! ODM for Mongo
![Page 31: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/31.jpg)
Template Engine Volt
! Volt is an ultra-‐fast and designer friendly templamng language wriNen in C for PHP. (TWIG Extension only one method)
! Volt is inspired by Jinja (Python)
![Page 32: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/32.jpg)
Phalcon Development Tools
! WebDevTools
![Page 33: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/33.jpg)
Phalcon Development Tools
! Command Line Tools
![Page 34: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/34.jpg)
Console Applicamon
! Single / Mulm Module Console Applicamons
! cronjobs
! Daemon Applicamon ! Long-‐life applicamon , using supervisor and kill yourself.
! Job Workers ! Using supervisor and kill yourself.
![Page 35: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/35.jpg)
CLI Launcher
![Page 36: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/36.jpg)
CLI MainTask
Php console.php // MainTask::mainAcmon
Php console.php main test // MainTask::testAcmon
![Page 37: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/37.jpg)
Phalcon Kernel
![Page 38: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/38.jpg)
Phalcon Kernel(2012~)
! 2012 PHPConfTW ! Phalcon 0.5.x Source Code 分離出來的專案。
! hNps://github.com/racklin/phalcon_kernel
! Ant 的 phpWowExtension 專案。 ! hNps://github.com/y8zeng/phpWowExtension
![Page 39: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/39.jpg)
Phalcon Kernel(~2012)
! 2012 PHPConfTW ! Phalcon 0.5.x Source Code 分離出來的專案。
! hNps://github.com/racklin/phalcon_kernel
! Ant 的 phpWoWExtension 專案。 ! hNps://github.com/y8zeng/phpWowExtension
![Page 40: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/40.jpg)
Phalcon Kernel(2012~)
! hNps://github.com/phalcon/cphalcon/blob/master/ext/kernel/README.md
Phalcon Kernel is a meta-‐framework on top of the Zend API helping to create PHP extensions in an easier way for a PHP developer. In order to build a fast and stable framework, we have created the Phalcon Kernel. The use of this API helps us to write C code in a PHP style. We have developed a number of funcmons to help the programmer to write code more interoperable with PHP in a easier way. Phalcon Kernel API is based on the Zend API, but we have added more features to facilitate us the work. Phalcon is a very large project, frameworks need to be developed and improved every day, Phalcon Kernel API helps us to write C code that is more stable and familiar to PHP developers.
![Page 41: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/41.jpg)
Phalcon Kernel(2012~)
! 基於 ZEND API
! 提供大量 Helper funcmons / macros
! php style 的 c 開發風格
![Page 42: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/42.jpg)
Zend API
![Page 43: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/43.jpg)
眼皮忍耐一下!
![Page 44: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/44.jpg)
![Page 45: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/45.jpg)
zval
![Page 46: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/46.jpg)
PHP> $greemng
![Page 47: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/47.jpg)
Data Types
Long Boolean Double String value
ZVAL_LONG() ZVAL_BOOL() ZVAL_DOUBLE() ZVAL_STRING()
NULL
ZVAL_NULL()
Create macro
![Page 48: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/48.jpg)
Data Types
Long Boolean Double String value String Length
Z_LVAL() Z_BVAL() Z_DVAL() Z_STRVAL() Z_STRLEN()
Z_LVAL_P() Z_BVAL_P() Z_DVAL_P() Z_STRVAL_P() Z_STRLEN_P()
HashTable Object
Z_ARRVAL() Z_OBJVAL()
Z_ARRVAL_P() Z_OBJVAL_P()
GeNer and Idenmfy macro
IdenLfy BOOL Long Double String NULL
Z_TYPE() IS_BOOL IS_LONG IS_DOUBLE IS_STRING IS_NULL
Z_TYPE_P()
![Page 49: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/49.jpg)
Return Types
Macro Type
RETURN_FALSE / RETURN_TRUE Boolean
RETURN_NULL() NULL
RETURN_LONG() Long
RETURN_DOUBLE() Double
RETURN_STRING() String
RETURN_CTOR() RETURN_CCTOR() RETURN_NCTOR()
ZVAL (Phalcon)
![Page 50: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/50.jpg)
Memory Management
! Phalcon Memory Management 簡化了 Zend Memory Managemant.
! PHALCON_MM_GROW() 建立一個 phalcon memory entry 結構
! PHALCON_INIT_VAR 建立並配置記憶體給 zval 並將其設為 null, 且將其指標的指標存至 phalcon memory entry.
! PHALCON_MM_RESTORE 釋放所有經由 PHALCON_INIT_VAR 配置且 refcount =1 的記憶體
![Page 51: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/51.jpg)
MM Sample
![Page 52: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/52.jpg)
MM Sample
![Page 53: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/53.jpg)
String
! ZVAL_STRING() – Zend API
! concat_funcmon – Zend API
! Concat macro
PHALCON_INIT_VAR(month); ZVAL_STRING(month, "2012", 1); PHALCON_INIT_VAR(today_is); ZVAL_STRING(today_is, "Today is", 1);
PHALCON_INIT_VAR(first_part); concat_funcmon(first_part, today_is, month);
PHALCON_INIT_VAR(today); PHALCON_CONCAT_SVSV(today, "Today is", month, " ", day);
![Page 54: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/54.jpg)
Concat Macros #define PHALCON_CONCAT_SV(result, op1, op2) \ #define PHALCON_CONCAT_SVS(result, op1, op2, op3) \ #define PHALCON_CONCAT_SVSV(result, op1, op2, op3, op4) \ #define PHALCON_CONCAT_SVSVS(result, op1, op2, op3, op4, op5) \ #define PHALCON_CONCAT_SVSVSV(result, op1, op2, op3, op4, op5, op6) \ #define PHALCON_CONCAT_SVSVSVS(result, op1, op2, op3, op4, op5, op6, op7) \ #define PHALCON_CONCAT_SVSVV(result, op1, op2, op3, op4, op5) \ #define PHALCON_CONCAT_SVV(result, op1, op2, op3) \ #define PHALCON_CONCAT_VS(result, op1, op2) \ #define PHALCON_CONCAT_VSV(result, op1, op2, op3) \ #define PHALCON_CONCAT_VSVS(result, op1, op2, op3, op4) \ #define PHALCON_CONCAT_VSVSVS(result, op1, op2, op3, op4, op5, op6) \ #define PHALCON_CONCAT_VSVSVSV(result, op1, op2, op3, op4, op5, op6, op7) \ #define PHALCON_CONCAT_VV(result, op1, op2) \ #define PHALCON_CONCAT_VVSV(result, op1, op2, op3, op4) \ #define PHALCON_CONCAT_VVV(result, op1, op2, op3) \ #define PHALCON_CONCAT_VVVVV(result, op1, op2, op3, op4, op5) \
![Page 55: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/55.jpg)
Arrays
! array_init(zval*) – inimal as array
! Add to array ! add_next_index_long / add_next_index_double ! add_next_index_bool / add_next_index_stringl
! Get (index type) (*string length) ! phalcon_array_fetch_long / phalcon_array_fetch_string
! Update (index type) (*string length) ! phalcon_array_update_long / phalcon_array_update_string
! Isset / unset (*string size) ! phalcon_array_isset_long / phalcon_array_isset_string ! phalcon_array_unset / phalcon_array_unset_string
![Page 56: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/56.jpg)
Call Funcmons
! PHALCON_CALL_FUNC 呼叫 PHP funcmon ,有回傳值
! PHALCON_CALL_FUNC_NORETURN 呼叫 PHP funcmon ,沒有回傳值
! PHALCON_CALL_FUNC_PARAMS_1 呼叫 PHP funcmon 並傳一個參數,有回傳值
! PHALCON_CALL_FUNC_PARAMS_1_NORETURN 呼叫 PHP funcmon 並傳一個參數,沒有回傳值
! 目前巨集定義到傳 3 個參數
![Page 57: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/57.jpg)
Call Funcmons
PHP Code
![Page 58: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/58.jpg)
Call Funcmons
![Page 59: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/59.jpg)
Call Methods
! PHALCON_CALL_METHOD 呼叫 PHP funcmon ,有回傳值
! PHALCON_CALL_METHOD_NORETURN 呼叫 PHP funcmon ,沒有回傳值
! PHALCON_CALL_METHOD_PARAMS_1 呼叫 PHP funcmon 並傳一個參數,有回傳值
! PHALCON_CALL_METHOD_PARAMS_1_NORETURN 呼叫 PHP funcmon 並傳一個參數,沒有回傳值
! 目前巨集定義到傳 5 個參數
![Page 60: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/60.jpg)
Call Methods
![Page 61: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/61.jpg)
OK! Wake UP!
![Page 62: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/62.jpg)
c9s ValidamonKit hNps://github.com/c9s/ValidamonKit
c extension DEMO
速度快 3 倍
![Page 63: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/63.jpg)
寫 C 就像談戀愛
即期待 又怕受傷害
![Page 64: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/64.jpg)
大部份人對於 C
![Page 65: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/65.jpg)
Zephir
![Page 66: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/66.jpg)
大海賊 DSL 時代來臨
! Javascript ! CoffeeScript , LiveScript , TypeScript.
! Java ! Scala , Groovy, Clojure
! GNOME GObject C ! Vala
! Zend Engine C ! Zephir
![Page 67: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/67.jpg)
Zephir
! Zephir -‐ Ze(nd Engine) Ph(p) I(nte)r(mediate)
! A high level language that eases the creamon and maintainability of extensions for PHP.
! Zephir extensions are exported to C code that can be compiled and opmmized by major C compilers such as gcc/clang/vc++
![Page 68: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/68.jpg)
CompilaLon Scheme
![Page 69: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/69.jpg)
Hello World!
![Page 70: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/70.jpg)
Hello World!
開頭少了 <?php 語法幾乎相同。
![Page 71: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/71.jpg)
Hello World Generated C
![Page 72: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/72.jpg)
Zephir -‐ PHP Syntax Like
![Page 73: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/73.jpg)
Generated C
![Page 74: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/74.jpg)
Zephir features
! Stamc/Dynamic typing
! Automamc memory management
! Produce object-‐oriented libraries that can be used in PHP
! Produce faster and beNer code that can be compiled by most important C-‐compilers: (gcc, vc++, clang)
! The syntax of Zephir is inspired by C, PHP, Rust and Javascript.
! Make the code more debugable ?????? (Without source map)
![Page 75: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/75.jpg)
Basic
! Organizing Code in Files and Namespaces ! Every file must contain a class (and just one class). ! Every class must have a namespace ! The directory structure must match the names of classes and
namespaces used. ( NOT Follow PSR-‐0)
![Page 76: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/76.jpg)
Variable DeclaraLons
! Declaramons
![Page 77: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/77.jpg)
Variable Assignment
! Assignment / Value Change
! MUST Using let keyword.
![Page 78: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/78.jpg)
Dynamic Types
![Page 79: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/79.jpg)
Stamc Types
![Page 80: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/80.jpg)
Arrays
![Page 81: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/81.jpg)
Hashes
NOT PHP k => v NOT JSON
![Page 82: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/82.jpg)
For Statement
! A ‘for’ is a control structure that allows to traverse arrays or strings
!
! Keys in hashes can be obtained in the following way:
![Page 83: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/83.jpg)
Calling FuncLons
! To call a PHP funcmon, you can just refer its name in the Zephir
![Page 84: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/84.jpg)
Create Zephir Project
! zephir init – Inimal zephir project and create config.json
! zephir [compile] – Compile and Install compiled .so .
![Page 85: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/85.jpg)
DEMO
Hello World!
Encoder / Decoder Extension (自己動手,別花錢買 ionCube 啦)
![Page 86: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/86.jpg)
b2p
go back to PHP
![Page 87: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/87.jpg)
Phalcon 2.0
! Phalcon 2.0 is currently being rewriNen in Zephir.
![Page 88: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/88.jpg)
Phalcon 2.0
! Phalcon 2.0 is currently being rewriNen in Zephir.
![Page 89: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/89.jpg)
Is Zephir produc0on-‐ready
! No, it’s in a very alpha stage.
! Phalcon Kernel is producmon-‐ready.
! If you review generated c sources, it’s producmon-‐ready.
! Keep Zephir in mind.
![Page 90: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/90.jpg)
![Page 91: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/91.jpg)
References
! Phalcon-‐dev-‐box: ! hNps://github.com/racklin/phalcon-‐dev-‐box
! PHPConfTW2013 sample Codes: ! hNps://github.com/racklin/phpcon8w2013
! Slides: ! hNps://speakerdeck.com/racklin/zephir-‐jian-‐jie
![Page 92: Phalcon / Zephir Introduction at PHPConfTW2013](https://reader034.vdocuments.site/reader034/viewer/2022042713/5467c8d6af79591f378b70d2/html5/thumbnails/92.jpg)
Thank You