SlideShare a Scribd company logo
Phalcon
The	
  Fastest	
  PHP	
  Framework
Rack	
  Lin	
  阿土伯	
  
@phpcon8w2013
about:me
!   目前為 ViViPOS	
  Co.,	
  Ltd	
  技術總監	
  
!   利用 javascript	
  寫 〞收銀機〞(傳統產業,全新感受)	
  
!   PHP	
  /	
  Javascript	
  /	
  Java	
  Programmer	
  (目前移情於 Scala	
  )	
  
! racklin@gmail.com	
  
! hNps://twiNer.com/racklin	
  
! hNps://www.facebook.com/racklin1002	
  
! hNp://racklin.blogspot.tw/	
  	
  	
  (生小孩後就變癈墟)	
  
2012	
  cphalcon	
  contributors
2013	
  cphalcon	
  contributors
 
學如逆⽔水⾏行⾈舟、不進則退	
  
	
  
在 Open	
  Source	
  更是如此
	
  
Phalcon	
  Framework	
  
Phalcon	
  Kernel	
  
Zephir	
  
Phalcon	
  Dev	
  Box
!   Virtual	
  Machine	
  for	
  PhalconPHP	
  Development	
  
! hNps://github.com/racklin/phalcon-­‐dev-­‐box	
  
!   Vagrant	
  /	
  VirtualBox	
  
Phalcon	
  Benefits	
  
!  The	
  Fastest	
  
!  Few	
  Memory	
  Usage	
  
!  Cross-­‐PlaZorm	
  
!  Highly	
  Decoupled	
  
!   Full-­‐stack	
  Framework	
  
C 實作
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
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	
  
所以結論…
	
  
為了快!專案要用 c	
  /	
  c++	
  來寫	
  web	
  	
  
Raphters
!   A	
  web	
  framework	
  for	
  C
除了慣C哥 
	
  
	
  
大部份人打完招呼	
  
Hello	
  World!	
  
不知道要做什麼…..
Fibonacci	
  as	
  php	
  extension
Fibonacci	
  as	
  php	
  extension
0m0.79s	
  	
  	
  	
  馬上變成第二名
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	
  
速度只要出問題,	
  C	
  都能搞定
 
平衡	
  

A	
  PHP	
  web	
  framework	
  	
  
delivered	
  as	
  a	
  C	
  extension	
  
Frameworks	
  benchmark
Frameworks	
  benchmark
 速度不是問題?
Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013
Raspberry	
  Pi
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
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	
  
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	
  
Highly	
  Decoupled
!   Ex.	
  Validamon
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	
  
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)	
  
Phalcon	
  Development	
  Tools
! WebDevTools	
  
Phalcon	
  Development	
  Tools
!   Command	
  Line	
  Tools	
  
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.	
  
	
  
CLI	
  Launcher
CLI	
  MainTask
Php	
  console.php	
  	
  //	
  MainTask::mainAcmon	
  
Php	
  console.php	
  main	
  test	
  //	
  MainTask::testAcmon	
  
Phalcon	
  Kernel
Phalcon	
  Kernel(2012~)
!   2012	
  PHPConfTW	
  	
  
! Phalcon	
  0.5.x	
  Source	
  Code	
  分離出來的專案。	
  
! hNps://github.com/racklin/phalcon_kernel	
  
!   Ant	
  的 phpWowExtension	
  專案。	
  
! hNps://github.com/y8zeng/phpWowExtension	
  
Phalcon	
  Kernel(~2012)
!   2012	
  PHPConfTW	
  	
  
! Phalcon	
  0.5.x	
  Source	
  Code	
  分離出來的專案。	
  
! hNps://github.com/racklin/phalcon_kernel	
  
!   Ant	
  的 phpWoWExtension	
  專案。	
  
! hNps://github.com/y8zeng/phpWowExtension	
  
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.	
  
Phalcon	
  Kernel(2012~)
!   基於 ZEND	
  API	
  
!   提供大量 Helper	
  funcmons	
  /	
  macros	
  
! php	
  style	
  	
  的 c	
  開發風格 	
  
Zend	
  API
眼皮忍耐一下!
	
  
	
  
Phalcon / Zephir Introduction at PHPConfTW2013
zval
PHP>	
  	
  	
  	
  $greemng
Data	
  Types
Long
 Boolean
 Double
 String	
  value
ZVAL_LONG()
 ZVAL_BOOL()
 ZVAL_DOUBLE()
 ZVAL_STRING()
NULL
ZVAL_NULL()
Create	
  macro
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()
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)
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	
  的記
憶體
MM	
  Sample
MM	
  Sample
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);	
  
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)	
  
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	
  
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 個參數	
  
Call	
  Funcmons
PHP	
  Code
Call	
  Funcmons
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	
  個參數	
  
Call	
  Methods
OK!	
  Wake	
  UP!
c9s	
  ValidamonKit
hNps://github.com/c9s/ValidamonKit	
  
	
  
c	
  extension	
  DEMO	
  
	
  
速度快 3	
  倍	
  
	
  
寫 C	
  就像談戀愛	
  
	
  
即期待	
  
又怕受傷害	
  
大部份人對於 C
Zephir
大海賊 DSL	
  時代來臨
! Javascript	
  
! CoffeeScript	
  ,	
  LiveScript	
  ,	
  	
  TypeScript.	
  
!   Java	
  
! Scala	
  ,	
  Groovy,	
  Clojure	
  
!   GNOME	
  GObject	
  C	
  
! Vala	
  
! Zend	
  Engine	
  C	
  
! Zephir	
  
	
  
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++
CompilaLon	
  Scheme
Hello	
  World!
Hello	
  World!
開頭少了 <?php	
  	
  
語法幾乎相同。
Hello	
  World	
  Generated	
  C
Zephir	
  -­‐	
  PHP	
  Syntax	
  Like
Generated	
  C
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)
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)	
  
Variable	
  DeclaraLons
!   Declaramons
Variable	
  Assignment
!   Assignment	
  /	
  Value	
  Change	
  
!   MUST	
  Using	
  	
  let	
  keyword.
Dynamic	
  Types
Stamc	
  Types
Arrays
Hashes
NOT	
  PHP	
  	
  	
  	
  k	
  =>	
  v	
  
NOT	
  JSON	
  
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:	
  
	
  
Calling	
  FuncLons
!   To	
  call	
  a	
  PHP	
  funcmon,	
  you	
  can	
  just	
  refer	
  its	
  name	
  in	
  the	
  Zephir	
  
Create	
  Zephir	
  Project
! zephir	
  init	
  –	
  Inimal	
  zephir	
  project	
  and	
  create	
  config.json	
  
! zephir	
  [compile]	
  –	
  Compile	
  and	
  Install	
  compiled	
  .so	
  .
DEMO
	
  
Hello	
  World!	
  
	
  
Encoder	
  /	
  Decoder	
  Extension	
  
	
  (自己動手,別花錢買 ionCube	
  啦)
b2p
	
  go	
  back	
  to	
  PHP
Phalcon	
  2.0
! Phalcon	
  2.0	
  is	
  currently	
  being	
  rewriNen	
  in	
  Zephir.
Phalcon	
  2.0
! Phalcon	
  2.0	
  is	
  currently	
  being	
  rewriNen	
  in	
  Zephir.
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.	
  
	
  
Phalcon / Zephir Introduction at PHPConfTW2013
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	
  
Thank	
  You

More Related Content

PDF
Php phalcon - Another approach to develop website - Techcamp Saigon 2014
PPTX
Phalcon - Giant Killer
PPTX
Phalcon overview
PDF
Php Conference Brazil - Phalcon Giant Killer
PPTX
Phalcon 2 - PHP Brazil Conference
PPTX
Php framework at BarCampPP
PDF
10 less-known Laravel Packages: April 2016
PPTX
Introduction of laravel framework.
Php phalcon - Another approach to develop website - Techcamp Saigon 2014
Phalcon - Giant Killer
Phalcon overview
Php Conference Brazil - Phalcon Giant Killer
Phalcon 2 - PHP Brazil Conference
Php framework at BarCampPP
10 less-known Laravel Packages: April 2016
Introduction of laravel framework.

What's hot (20)

PPTX
Web development with Python
PDF
Console Apps: php artisan forthe:win
PDF
All the Laravel Things – Up & Running to Making $$
PDF
How composer saved PHP
PDF
Pharo JS
PDF
Joomlatools Platform v2.0
PDF
All the Laravel things: up and running to making $$
PDF
Fresh Laravel packages - September 2016
PDF
Reverse Installing CPAN
PDF
10 Fresh laravel packages - October 2016
PDF
What’s new in laravel 9
PDF
Laravel 5 New Features
PDF
Complete WPF Overview Tutorial with Example - iFour Technolab
PPTX
[Part 1] automation of home appliances using raspberry pi – software installa...
PDF
Laravel Code Generators and Packages
ODP
The Ultimate iOS 11 Course Learn to Build Apps
PDF
Php Dependency Management with Composer ZendCon 2016
PPTX
10 Laravel packages everyone should know
PPTX
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
PPTX
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
Web development with Python
Console Apps: php artisan forthe:win
All the Laravel Things – Up & Running to Making $$
How composer saved PHP
Pharo JS
Joomlatools Platform v2.0
All the Laravel things: up and running to making $$
Fresh Laravel packages - September 2016
Reverse Installing CPAN
10 Fresh laravel packages - October 2016
What’s new in laravel 9
Laravel 5 New Features
Complete WPF Overview Tutorial with Example - iFour Technolab
[Part 1] automation of home appliances using raspberry pi – software installa...
Laravel Code Generators and Packages
The Ultimate iOS 11 Course Learn to Build Apps
Php Dependency Management with Composer ZendCon 2016
10 Laravel packages everyone should know
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
Ad

Viewers also liked (13)

PPTX
NoSQL-MongoDB介紹
PDF
ECMAScript 6
PPTX
JCConf 2015 TW 高效率資料爬蟲組合包
PDF
那些年,我們一起搞的金流
PPTX
Elasticsearch 簡介
PDF
Chrome 佛心做了 Devtool 就是要用啊? 從 Timeline 學調效動畫效能
PPTX
網站自動化測試
PDF
周世恩/資料分析前的奏曲 : 談資料收集的挑戰
PDF
[系列活動] 文字探勘者的入門心法
PDF
提到 DevOps 到底在
談些什麼玩意兒?(@ Agile Tour Taichung 2017)
PDF
Elasticsearch 簡介
PDF
Seo 最重要的檢查項目
PDF
姜俊宇/從資料到知識:從零開始的資料探勘
NoSQL-MongoDB介紹
ECMAScript 6
JCConf 2015 TW 高效率資料爬蟲組合包
那些年,我們一起搞的金流
Elasticsearch 簡介
Chrome 佛心做了 Devtool 就是要用啊? 從 Timeline 學調效動畫效能
網站自動化測試
周世恩/資料分析前的奏曲 : 談資料收集的挑戰
[系列活動] 文字探勘者的入門心法
提到 DevOps 到底在
談些什麼玩意兒?(@ Agile Tour Taichung 2017)
Elasticsearch 簡介
Seo 最重要的檢查項目
姜俊宇/從資料到知識:從零開始的資料探勘
Ad

Similar to Phalcon / Zephir Introduction at PHPConfTW2013 (20)

PPTX
PHP Conference - Phalcon hands-on
PPTX
Modern Frontend Technology
PPT
An Introduction to Websphere sMash for PHP Programmers
PDF
Unleash your Symfony projects with eZ Platform
PDF
Why scala is not my ideal language and what I can do with this
PDF
Appenginejs (old presentation)
PDF
JavaOne - The JavaFX Community and Ecosystem
PDF
2013 - Dustin whittle - Escalando PHP en la vida real
PDF
Php through the eyes of a hoster confoo
PDF
25 Intro to Symfony #burningkeyboards
PDF
Integrating Applications: the Reactive Way
PPTX
Web Dev 21-01-2024.pptx
PPT
Lamp Zend Security
PDF
Web Frameworks of the Future
PPT
Eclipse - Single Source;Three Runtimes
PDF
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
PDF
Apache Deep Learning 201 - Barcelona DWS March 2019
PPT
AppengineJS
PDF
Symfony 2.0 on PHP 5.3
PDF
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
PHP Conference - Phalcon hands-on
Modern Frontend Technology
An Introduction to Websphere sMash for PHP Programmers
Unleash your Symfony projects with eZ Platform
Why scala is not my ideal language and what I can do with this
Appenginejs (old presentation)
JavaOne - The JavaFX Community and Ecosystem
2013 - Dustin whittle - Escalando PHP en la vida real
Php through the eyes of a hoster confoo
25 Intro to Symfony #burningkeyboards
Integrating Applications: the Reactive Way
Web Dev 21-01-2024.pptx
Lamp Zend Security
Web Frameworks of the Future
Eclipse - Single Source;Three Runtimes
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
Apache Deep Learning 201 - Barcelona DWS March 2019
AppengineJS
Symfony 2.0 on PHP 5.3
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25-Week II
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Review of recent advances in non-invasive hemoglobin estimation
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 3 Spatial Domain Image Processing.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Assigned Numbers - 2025 - Bluetooth® Document
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Phalcon / Zephir Introduction at PHPConfTW2013

  • 1. Phalcon The  Fastest  PHP  Framework Rack  Lin  阿土伯   @phpcon8w2013
  • 2. about:me !   目前為 ViViPOS  Co.,  Ltd  技術總監   !   利用 javascript  寫 〞收銀機〞(傳統產業,全新感受)   !   PHP  /  Javascript  /  Java  Programmer  (目前移情於 Scala  )   ! [email protected]   ! hNps://twiNer.com/racklin   ! hNps://www.facebook.com/racklin1002   ! hNp://racklin.blogspot.tw/      (生小孩後就變癈墟)  
  • 6. Phalcon  Framework   Phalcon  Kernel   Zephir  
  • 7. Phalcon  Dev  Box !   Virtual  Machine  for  PhalconPHP  Development   ! hNps://github.com/racklin/phalcon-­‐dev-­‐box   !   Vagrant  /  VirtualBox  
  • 8. Phalcon  Benefits   !  The  Fastest   !  Few  Memory  Usage   !  Cross-­‐PlaZorm   !  Highly  Decoupled   !   Full-­‐stack  Framework   C 實作
  • 9. 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
  • 10. 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  
  • 11. 所以結論…   為了快!專案要用 c  /  c++  來寫  web    
  • 12. Raphters !   A  web  framework  for  C
  • 13. 除了慣C哥     大部份人打完招呼   Hello  World!   不知道要做什麼…..
  • 14. Fibonacci  as  php  extension
  • 15. Fibonacci  as  php  extension 0m0.79s        馬上變成第二名
  • 16. 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  
  • 18.   平衡   A  PHP  web  framework     delivered  as  a  C  extension  
  • 26. 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
  • 27. 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  
  • 28. 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  
  • 29. Highly  Decoupled !   Ex.  Validamon
  • 30. 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  
  • 31. 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)  
  • 33. Phalcon  Development  Tools !   Command  Line  Tools  
  • 34. 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.    
  • 36. CLI  MainTask Php  console.php    //  MainTask::mainAcmon   Php  console.php  main  test  //  MainTask::testAcmon  
  • 38. Phalcon  Kernel(2012~) !   2012  PHPConfTW     ! Phalcon  0.5.x  Source  Code  分離出來的專案。   ! hNps://github.com/racklin/phalcon_kernel   !   Ant  的 phpWowExtension  專案。   ! hNps://github.com/y8zeng/phpWowExtension  
  • 39. Phalcon  Kernel(~2012) !   2012  PHPConfTW     ! Phalcon  0.5.x  Source  Code  分離出來的專案。   ! hNps://github.com/racklin/phalcon_kernel   !   Ant  的 phpWoWExtension  專案。   ! hNps://github.com/y8zeng/phpWowExtension  
  • 40. 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.  
  • 41. Phalcon  Kernel(2012~) !   基於 ZEND  API   !   提供大量 Helper  funcmons  /  macros   ! php  style    的 c  開發風格  
  • 45. zval
  • 46. PHP>        $greemng
  • 47. Data  Types Long Boolean Double String  value ZVAL_LONG() ZVAL_BOOL() ZVAL_DOUBLE() ZVAL_STRING() NULL ZVAL_NULL() Create  macro
  • 48. 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()
  • 49. 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)
  • 50. 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  的記 憶體
  • 53. 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);  
  • 54. 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)  
  • 55. 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  
  • 56. 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 個參數  
  • 59. 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  個參數  
  • 62. c9s  ValidamonKit hNps://github.com/c9s/ValidamonKit     c  extension  DEMO     速度快 3  倍    
  • 63. 寫 C  就像談戀愛     即期待   又怕受傷害  
  • 66. 大海賊 DSL  時代來臨 ! Javascript   ! CoffeeScript  ,  LiveScript  ,    TypeScript.   !   Java   ! Scala  ,  Groovy,  Clojure   !   GNOME  GObject  C   ! Vala   ! Zend  Engine  C   ! Zephir    
  • 67. 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++
  • 70. Hello  World! 開頭少了 <?php     語法幾乎相同。
  • 72. Zephir  -­‐  PHP  Syntax  Like
  • 74. 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)
  • 75. 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)  
  • 77. Variable  Assignment !   Assignment  /  Value  Change   !   MUST  Using    let  keyword.
  • 81. Hashes NOT  PHP        k  =>  v   NOT  JSON  
  • 82. 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:    
  • 83. Calling  FuncLons !   To  call  a  PHP  funcmon,  you  can  just  refer  its  name  in  the  Zephir  
  • 84. Create  Zephir  Project ! zephir  init  –  Inimal  zephir  project  and  create  config.json   ! zephir  [compile]  –  Compile  and  Install  compiled  .so  .
  • 85. DEMO   Hello  World!     Encoder  /  Decoder  Extension    (自己動手,別花錢買 ionCube  啦)
  • 86. b2p  go  back  to  PHP
  • 87. Phalcon  2.0 ! Phalcon  2.0  is  currently  being  rewriNen  in  Zephir.
  • 88. Phalcon  2.0 ! Phalcon  2.0  is  currently  being  rewriNen  in  Zephir.
  • 89. 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.    
  • 91. 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