SlideShare ist ein Scribd-Unternehmen logo
1 von 81
Downloaden Sie, um offline zu lesen
Phalcon	
  PHP	
  Framework	
  
     The	
  Fastest	
  Faster	
  PHP	
  Framework




                                         阿土伯
about:me
!   目前為 ViViPOS	
  Co.,	
  Ltd	
  技術總監	
  
    !   利用 javascript	
  寫 〞收銀機〞(傳統產業,全新感受)	
  
        !      CoCo	
  都可、50嵐、歇腳亭、Yamaha	
  、星聚點	
  KTV	
  
        	
  

!   #3	
  commiHer	
  of	
  cphalcon	
  repository	
  

!   PHP	
  /	
  Javascript	
  /	
  Java	
  Programmer	
  (目前移情於 Scala	
  )	
  
! racklin@gmail.com	
  
! hHps://twiHer.com/racklin	
  

! hHps://www.facebook.com/racklin1002	
  

! hHp://racklin.blogspot.tw/	
  	
  	
  (生小孩後就變癈墟)	
  
議題
! PhalconPHP	
  Framework 介紹	
  

! PhalconPHP	
  Kernel 介紹	
  

!   DEMO	
  c9s	
  ValidaWonKit	
  porWng	
  as	
  php	
  extension	
  
Programmers	
  共同的罩門	
  
!  速度最快!	
  
!  使用資源最小!	
  
!  跨平台!	
  
	
  
Programmers	
  共同的罩門	
  
!  速度最快!	
  
!  使用資源最小!	
  
!  跨平台!	
  
	
  
	
     所以大家來聽 PhalconPHP	
  
為什麼快
!   Fibonacci	
  40	
  (費式數列)	
  hHp://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

500	
  

400	
  

300	
  

200	
  

100	
  

    0	
  
            c	
  with	
  -­‐   java	
     scala	
   nodejs	
     ruby	
   php	
  5.4	
   ruby	
   php	
  5.3	
  
                 O2	
                                            1.9.2	
                 1.8.x	
  
所以結論…
       	
  
下一個專案要用 c	
  /	
  c++	
  來寫	
  web	
  	
  
Raphters
!   A	
  web	
  framework	
  for	
  C
WOW!	
  COOOOOOL~
   看起來好像很容易!
除了慣C哥 
        	
  
        	
  
大部份人打完招呼不知道要做什麼…..
PHP	
  沒救了?
Fibonacci	
  as	
  php	
  extension
Fibonacci	
  as	
  php	
  extension




    0m0.79s	
  	
  	
  	
  馬上變成第二名
Fibonacci	
  圖表

450	
  
400	
  
350	
  
300	
  
250	
  
200	
  
150	
  
100	
  
 50	
  
  0	
  
          c	
  with	
  -­‐O2	
   java	
     scala	
   nodejs	
  
                                                            ruby	
  1.9.2	
   5.4	
  
                                                                        php	
   ruby	
  1.8.x	
   5.3	
  php	
  ext	
  
                                                                                            php	
  
速度只要出問題,	
  C	
  都能搞定
漂亮的平衡	
  
       
 A	
  PHP	
  web	
  framework	
  	
  
delivered	
  as	
  a	
  C	
  extension
PHP	
  extension	
  frameworks
              	
  
         PhalconPHP	
  
             Yaf
為什麼不是 Yaf
!   Underscore	
  Class	
  Name	
  (	
  目標 PHP	
  5.2 和以上版本)	
  

!   Document 實在不多	
  

!   Sample	
  Codes	
  	
  更少	
  

	
  
為什麼不是 Yaf
!   Underscore	
  Class	
  Name	
  ( 目標 PHP	
  5.2 和以上版本)	
  

!   Document 實在不多	
  

!   Sample	
  Codes	
  	
  更少	
  

	
  

!   Yet	
  Another	
  Framework	
  (Yaf)	
  
    	
  
    這專案名稱我不喜歡	
  
    很怕將來會出一個	
  What	
  The	
  Framework	
  (WTx)	
  
Frameworks	
  benchmark
Frameworks	
  memory	
  usage
PhalconPHP	
  benefits
!   PHP	
  Extension	
  –	
  Faster	
  

! Phalcon	
  all	
  Components	
  are	
  loosely	
  coupled	
  

!   Low-­‐Level	
  OpWmizaWons	
  

!   Using	
  c-­‐language	
  ORM	
  for	
  PHP	
  

!   PHQL	
  –	
  lemon	
  parser	
  (SQLite)	
  

!   Well-­‐documented	
  
PhalconPHP	
  0.5	
  news
!   Namespaces	
  

!   Class	
  Loader	
  –	
  相容於 PSR-­‐0	
  

!   Dependency	
  Injec8on	
  

!   Events	
  Manager	
  

!   PDO	
  Database	
  Adapters	
  
    !   *	
  支援 SQLite.	
  	
  	
  
    !   *	
  PostgreSQL	
  支援 Mul8-­‐Schemas	
  

!   *	
  CLI	
  Applica8ons	
  

!   Micro	
  Applica8ons	
  
!   Full	
  stack	
  frameworks	
  
PhalconPHP	
  0.6
!   Object-­‐Document	
  Mapper	
  -­‐	
  MongoDB	
  

!   Volt:	
  Template	
  Engine	
  	
  -­‐	
  inspired	
  on	
  Twig	
  




!   PS.	
  11/2	
  Released	
  
Class	
  Loader	
  
Dependency	
  InjecWon	
  
  Events	
  Manager
               	
  
               	
  
               	
  
            Flexible	
  
          Extensible	
  
          Plugin-­‐able	
  	
  
Class	
  Loader
!   盡可能不用使用 include	
  /	
  require	
  .	
  

! registerNamespaces	
  –	
  PSR-­‐0	
  相容	
  

! registerPrefixes	
  

! registerClasses	
  

! registerDirectories	
  
Using	
  Class	
  Loader
Composer
•  類似 PEAR	
  的套件管理工具,但更方便! 像是 npm	
  /	
  brew	
  。	
  
  •  Install	
  Composer	
  
        $	
  curl	
  -­‐s	
  hHps://getcomposer.org/installer	
  |	
  php


  •  IniWal	
  project	
  

        $	
  composer.phar	
  init

  •  Require	
  /	
  Install	
  libraries	
  
        $	
  composer.phar	
  require	
  [vendor/name]


  •  Update	
  libraries	
  
        $	
  composer.phar	
  update
Composer	
  Autoloading
•  只要加一行在你的程式中 	
  
  require	
  'vendor/autoload.php';




          hHps://packagist.org/
Phalcon	
  Class	
  Loader	
  +	
  	
  
                 Composer	
  Autloading
! Phalcon	
  and	
  Composer	
  都是使用 spl_autoload_register	
  ,	
  
  spl_autoload_register 相當聰明,載入類別後會中斷執行,
  不會重覆載入	
  

!   註冊 多個 autoload	
  handlers	
  是安全的	
  
    	
  
    	
  
    	
  

!   所以只要在 Phalcon	
  Class	
  Loader	
  前先加上一行即可	
  

	
     require	
  'vendor/autoload.php’;	
  
Dependency	
  InjecWon
!   PhalconDI	
  實作了 IoC	
  設計模式,幫助寫出可擴充性、易
    於測試、維護的程式碼。	
  

! PhalconPHP	
  內部大量利用 DI	
  將各元件串接起來。	
  

	
  
Dependency	
  InjecWon
!   產生新的物件或單例(Singleton) - get	
  /	
  getShared	
  

!   傳參數給	
  Constructor	
  

!   Lazy	
  loading	
  
     !   物件只有在被取得時才會產生	
  

!   Magic	
  	
  
     !   如果沒有註冊,會自動試著找同樣的 Class	
  Name	
  



!   如果可以,全部利用 DI	
  來產生您的類別實例。
DI	
  範例	
  (set)
DI	
  範例	
  (get)
!   取得物件	
  
    $request	
  =	
  $di-­‐>get("request");	
  

!   透過 magic	
  method	
  
    $request	
  =	
  $di-­‐>getRequest();	
  

!   Singleton	
  
    $request	
  =	
  $di-­‐>getShared("request");	
  

!   傳參數給 constructor	
  
    $component	
  =	
  $di-­‐>get("MyComponent",	
  array("some-­‐
    parameter",	
  "other"))
Events	
  Manager
!   Web	
  GUI	
  程式中,我們大量使用 Events 。	
  
    !   DOM	
  Events	
  

!   Events	
  Manager	
  -­‐	
  fire	
  event	
  ,	
  aHach	
  listener	
  

!   Event	
  Type	
  Using	
  colon	
  :	
  as	
  namespace	
  separator.	
  	
  
DEMO
!   Using	
  Class	
  Loader	
  	
  /	
  Dependency	
  InjecWon	
  /	
  Events	
  Manager	
  
    for	
  plugin-­‐able	
  applicaWons.	
  

!   Linux	
  Upstart	
  init	
  daemon	
  like	
  demo	
  
    hHp://upstart.ubuntu.com/	
  	
  (replacement	
  for	
  the	
  venerable	
  
    System-­‐V	
  init)	
  




!   Shopping-­‐Cart	
  Plugin-­‐able	
  PromoWons	
  .	
  
Micro	
  Framework
!   Simple	
  and	
  ResTul	
  

!   Frameworks	
  
    ! RubyàSinatra,	
  Cuba
    ! PythonàFlask,	
  Pyramid	
  
    !   PHP	
  àSilex,	
  Slim	
  
    !   Java	
  àNapalm	
  
Micro	
  Example




Not	
  Found	
  Handler
Full	
  Stack	
  Framework
!   MVC	
  Architecture	
  

!   Router	
  /	
  Dispatcher	
  

!   View	
  Helper	
  /	
  Template	
  Engine	
  

!   Filtering	
  Data	
  

!   Session	
  	
  

!   Cache	
  

!   ACL	
  

!   Logging	
  
!   I18n/l10n	
  
Models
CreaWng	
  Models




By	
  default	
  model	
  “Robots”	
  will	
  refer	
  to	
  the	
  table	
  “robots”.
Models
Finding	
  Records
Models
Save	
  changes
Models
Finding	
  with	
  condiWons	
  ,	
  order	
  and	
  Limit
Models
!   RelaWons	
  
Models
!   RelaWons	
  
Models
!   RelaWons	
  
Models	
  -­‐	
  Criteria
!   Similar	
  To	
  	
  
     !   Doctrine	
  QueryBuilder	
  
     ! Yii	
  Query	
  Object	
  

!   Provides	
  a	
  fluent	
  API.	
  
PHQL
!   Similar	
  To	
  	
  
     !   Doctrine	
  DQL	
  
     !   Hibernate	
  HQL	
  

! Phalcon	
  Query	
  Language	
  is	
  a	
  high	
  level,	
  object	
  oriented	
  SQL	
  
  dialect.	
  

!   High	
  performance,	
  Phalcon	
  provides	
  a	
  parser	
  that	
  uses	
  the	
  
    same	
  technology	
  as	
  SQLite.	
  (lemon	
  parser)	
  
    hHp://www.sqlite.org/src/doc/trunk/doc/lemon.html	
  
PHQL
Select	
  Records




Select	
  Records	
  with	
  namespaces
Controller
View	
  Helpers
  !   WriWng	
  and	
  maintaining	
  HTML	
  markup	
  can	
  quickly


Document	
  type




Produced
Template	
  Engine	
  -­‐	
  Volt
!   Volt	
  is	
  an	
  ultra-­‐fast	
  and	
  designer	
  friendly	
  templaWng	
  language	
  
    wriHen	
  in	
  C	
  ,	
  inspired	
  on	
  Twig.
Console	
  ApplicaWon
!   CLI	
  Components	
  



! cronjobs	
  

!   Daemon	
  ApplicaWon	
  
       !   Long-­‐life	
  applicaWon	
  ,	
  using	
  supervisor	
  and	
  kill	
  yourself.	
  

!   Job	
  Workers	
  
       !   Using	
  supervisor	
  and	
  kill	
  yourself.	
  

	
  
CLI	
  Launcher
CLI	
  MainTask




Php	
  console.php	
  	
  //	
  MainTask::mainAcWon	
  


Php	
  console.php	
  main	
  test	
  //	
  MainTask::testAcWon	
  
CLI	
  DEMO
PhalconPHP	
  Kernel
! hHps://github.com/racklin/phalcon_kernel	
  

!   由 cphalcon	
  中抽離出來的專案。	
  

!   提供大量基於 Zend	
  API	
  的巨集/工具。	
  

!   簡化 php	
  extension	
  開發。	
  
Why	
  Extension
!   Driver	
  /	
  Adapter	
  

!   Low-­‐level	
  NaWve	
  Code	
  Libraries	
  

!   Performance	
  

!   EncapsulaWon	
  /	
  InformaWon	
  Hidden	
  
    !   For	
  Developer	
  
    !   For	
  Customers	
  	
  
zval
c:	
  zval	
  *a	
  	
  	
  
 相當於	
  
 php:	
  $a
Data	
  Types
Create	
  macro

    Long
          Boolean
       Double
          String	
  value
    ZVAL_LONG()
   ZVAL_BOOL()
   ZVAL_DOUBLE()
   ZVAL_STRING()



    NULL
    ZVAL_NULL()
Data	
  Types
GeHer	
  and	
  IdenWfy	
  macro

     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()


     Iden8fy	
  
      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()	
                     ZVAL	
  (Phalcon)
RETURN_CCTOR()	
  
RETURN_NCTOR()
Memory	
  Management
! Phalcon	
  Memory	
  Management	
  簡化了 Zend	
  Memory	
  
  Managemant.	
  

!   PHALCON_MM_GROW()	
  
    建立一個 phalcon	
  memory	
  entry	
  結構	
  

!   PHALCON_INIT_VAR	
  /	
  PHALCON_ALLOC_ZVAL_MM	
  	
  
    建立並配置記憶體給 zval	
   並將其設為 null,	
  且將其指標的指
    標存至 phalcon	
  memory	
  entry.	
  

!   PHALCON_MM_RESTORE	
  
    釋放所有經由 PHALCON_INIT_VAR	
  配置且 refcount	
  =1	
  的記
    憶體
Phalcon	
  MM	
  Bad	
  Parts
!   PHALCON_ALLOC_ZVAL_MM	
  or	
  PHALCON_INIT_VAR	
  
       !   如果你 trace	
  source	
  code	
  二者差別只在於一個是先將 zval	
  
           pointer	
  pointer	
  放入 memory	
  entry	
  再設定初始值。一個是先設
           定初始值再將 zval	
  pointer	
  pointer	
  放入 memory	
  entry	
  ….	
  	
  
       !   PHALCON_INIT_VAR	
  3488	
  lines	
  
       !   PHALCON_ALLOC_ZVAL_MM	
  	
  	
  468	
  lines	
  

	
  
MM	
  Sample
String
!   ZVAL_STRING()	
  –	
  Zend	
  API	
  
           PHALCON_INIT_VAR(month);	
  	
  
	
         ZVAL_STRING(month,	
  "2012",	
  1);	
  
           PHALCON_INIT_VAR(today_is);	
  	
  
	
  	
     ZVAL_STRING(today_is,	
  "Today	
  is",	
  1);

! concat_funcWon	
  –	
  Zend	
  API	
  
           PHALCON_INIT_VAR(first_part);	
  
           concat_funcWon(first_part,	
  today_is,	
  month);

! Concat	
  macro	
  
           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*)	
  –	
  iniWal	
  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	
  
Phalcon	
  Arrays	
  Bad	
  Parts
!   PHP	
  String	
  is	
  Binary-­‐Safe	
  
    !   String	
  Length	
  =	
  Actually	
  String	
  Length	
  
    !   String	
  Size	
  =	
  String	
  Length	
  +	
  1	
  bytes(0)	
  

!   Arrays	
  fetch	
  and	
  update	
  using	
  String	
  Length	
  

!   Arrays	
  isset	
  and	
  unset	
  using	
  String	
  Size	
  

! Phalcon_array_unset	
  not	
  phalcon_array_unset_long
Call	
  FuncWons
!   PHALCON_CALL_FUNC	
  	
  
    呼叫 PHP	
  funcWon	
  ,有回傳值	
  

!   PHALCON_CALL_FUNC_NORETURN	
  
    呼叫 PHP	
  funcWon	
  ,沒有回傳值

!   PHALCON_CALL_FUNC_PARAMS_1	
  	
  
    呼叫 PHP	
  funcWon 並傳一個參數,有回傳值	
  

!   PHALCON_CALL_FUNC_PARAMS_1_NORETURN	
  
    呼叫 PHP	
  funcWon 並傳一個參數,沒有回傳值	
  

!   目前巨集定義到傳 3 個參數	
  
Call	
  FuncWons

   PHP	
  Code
Call	
  FuncWons
Call	
  Methods
!   PHALCON_CALL_METHOD	
  
    呼叫 PHP	
  funcWon ,有回傳值	
  

!   PHALCON_CALL_METHOD_NORETURN	
  
    呼叫 PHP	
  funcWon ,沒有回傳值

!   PHALCON_CALL_METHOD_PARAMS_1	
  	
  
    呼叫 PHP	
  funcWon 並傳一個參數,有回傳值	
  

!   PHALCON_CALL_METHOD_PARAMS_1_NORETURN	
  
    呼叫 PHP	
  funcWon 並傳一個參數,沒有回傳值	
  

!   目前巨集定義到傳 5	
  個參數	
  
Call	
  Methods
Object	
  ProperWes
!   Update	
  Property	
  
    !       	
  phalcon_update_property_long	
  
    !       	
  phalcon_update_property_bool	
  
    !       	
  phalcon_update_property_null	
  
    !       	
  phalcon_update_property_zval	
  /	
  
            phalcon_update_property_zval_zval	
  

!   Read	
  Property	
  
    !   	
  phalcon_read_property	
  /	
  phalcon_read_property_zval	
  

! Isset	
  Property	
  
    !   	
  phalcon_isset_property	
  /	
  phalcon_isset_property_zval	
  
PHP	
  Style
WriWng	
  c	
  extension
c9s	
  ValidaWonKit
 hHps://github.com/c9s/ValidaWonKit	
  
                      	
  
          c	
  extension	
  DEMO
References
!   Slide:	
  
    hHps://speakerdeck.com/racklin/phalcon-­‐php-­‐framework-­‐and-­‐
    phalcon-­‐kernel-­‐introducWon-­‐phpcon€w2012	
  

!   Sample	
  code:	
  
    hHps://github.com/racklin/phpcon€w2012_phalcon	
  

! PhalconPHP	
  internal:	
  	
  
  hHp://internals.phalconphp.com/en/latest/index.html	
  
Thank	
  You

Más contenido relacionado

Was ist angesagt?

从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型Jackson Tian
 
基于Symfony框架下的快速企业级应用开发
基于Symfony框架下的快速企业级应用开发基于Symfony框架下的快速企业级应用开发
基于Symfony框架下的快速企业级应用开发mysqlops
 
Laravel installfest 工作坊 投影片
Laravel installfest 工作坊 投影片Laravel installfest 工作坊 投影片
Laravel installfest 工作坊 投影片Shengyou Fan
 
大话Php之性能
大话Php之性能大话Php之性能
大话Php之性能liqiang xu
 
媽,我交了個大象朋友
媽,我交了個大象朋友媽,我交了個大象朋友
媽,我交了個大象朋友Shengyou Fan
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定Shengyou Fan
 
PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向Shengyou Fan
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvementsXinchen Hui
 
Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10
Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10
Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10Shengyou Fan
 
開發環境建置
開發環境建置開發環境建置
開發環境建置Shengyou Fan
 
test
testtest
testxieyq
 
給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由Shengyou Fan
 
微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)Xinchen Hui
 
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊Shengyou Fan
 
選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅Shengyou Fan
 
專案啟動與環境設定
專案啟動與環境設定專案啟動與環境設定
專案啟動與環境設定Shengyou Fan
 
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發俊仁 陳
 
COSCUP 2016 Laravel 部署工作坊 - 部署指南
COSCUP 2016 Laravel 部署工作坊 - 部署指南COSCUP 2016 Laravel 部署工作坊 - 部署指南
COSCUP 2016 Laravel 部署工作坊 - 部署指南Shengyou Fan
 

Was ist angesagt? (20)

从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
 
基于Symfony框架下的快速企业级应用开发
基于Symfony框架下的快速企业级应用开发基于Symfony框架下的快速企业级应用开发
基于Symfony框架下的快速企业级应用开发
 
Laravel installfest 工作坊 投影片
Laravel installfest 工作坊 投影片Laravel installfest 工作坊 投影片
Laravel installfest 工作坊 投影片
 
大话Php之性能
大话Php之性能大话Php之性能
大话Php之性能
 
媽,我交了個大象朋友
媽,我交了個大象朋友媽,我交了個大象朋友
媽,我交了個大象朋友
 
工作坊簡介
工作坊簡介工作坊簡介
工作坊簡介
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定
 
PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向
 
Weibo lamp improvements
Weibo lamp improvementsWeibo lamp improvements
Weibo lamp improvements
 
Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10
Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10
Laravel 台灣 南進台中 社群小聚 - 社群現況報馬仔 2015/10
 
開發環境建置
開發環境建置開發環境建置
開發環境建置
 
test
testtest
test
 
給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由給你一個使用 Laravel 的理由
給你一個使用 Laravel 的理由
 
微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)微博Lamp性能优化之路(2014)
微博Lamp性能优化之路(2014)
 
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
 
選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅選一個框架當好朋友,讓您成為開心攻城獅
選一個框架當好朋友,讓您成為開心攻城獅
 
專案啟動與環境設定
專案啟動與環境設定專案啟動與環境設定
專案啟動與環境設定
 
課程簡介
課程簡介課程簡介
課程簡介
 
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
 
COSCUP 2016 Laravel 部署工作坊 - 部署指南
COSCUP 2016 Laravel 部署工作坊 - 部署指南COSCUP 2016 Laravel 部署工作坊 - 部署指南
COSCUP 2016 Laravel 部署工作坊 - 部署指南
 

Andere mochten auch

Facebook dilemma presentation
Facebook dilemma presentationFacebook dilemma presentation
Facebook dilemma presentationdarioyunes
 
Six Sigma By Mhussain
Six Sigma By MhussainSix Sigma By Mhussain
Six Sigma By Mhussainhussainetd
 
20070502 takaful malaysia
20070502 takaful malaysia20070502 takaful malaysia
20070502 takaful malaysiaFarah Ain
 
Taxation implications for company paid healthcare for large employers
Taxation implications for company paid healthcare for large employersTaxation implications for company paid healthcare for large employers
Taxation implications for company paid healthcare for large employersSimplyhealthUK
 
Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013Rack Lin
 
Build desktop app_by_xulrunner
Build desktop app_by_xulrunnerBuild desktop app_by_xulrunner
Build desktop app_by_xulrunnerRack Lin
 
Wellbeing strategies in the workplace
Wellbeing strategies in the workplaceWellbeing strategies in the workplace
Wellbeing strategies in the workplaceSimplyhealthUK
 
改善Programmer生活的sql技能
改善Programmer生活的sql技能改善Programmer生活的sql技能
改善Programmer生活的sql技能Rack Lin
 
Simplyhealth's Annual Dental Survey 2011
Simplyhealth's Annual Dental Survey 2011Simplyhealth's Annual Dental Survey 2011
Simplyhealth's Annual Dental Survey 2011SimplyhealthUK
 
Plugin-able POS Solutions by Javascript @HDM9 Taiwan
Plugin-able POS Solutions by Javascript @HDM9 TaiwanPlugin-able POS Solutions by Javascript @HDM9 Taiwan
Plugin-able POS Solutions by Javascript @HDM9 TaiwanRack Lin
 
Personal Skills
Personal SkillsPersonal Skills
Personal Skillshussainetd
 
20070502 takaful malaysia
20070502 takaful malaysia20070502 takaful malaysia
20070502 takaful malaysiaFarah Ain
 
Use of Replication and Portable Hardness Testing for High Temperature Plant I...
Use of Replication and Portable Hardness Testing for High Temperature Plant I...Use of Replication and Portable Hardness Testing for High Temperature Plant I...
Use of Replication and Portable Hardness Testing for High Temperature Plant I...hussainetd
 
Personal Skills
Personal SkillsPersonal Skills
Personal Skillshussainetd
 
Pakistan Telecommunication Services
Pakistan Telecommunication ServicesPakistan Telecommunication Services
Pakistan Telecommunication Serviceshussainetd
 

Andere mochten auch (16)

research guide
research guideresearch guide
research guide
 
Facebook dilemma presentation
Facebook dilemma presentationFacebook dilemma presentation
Facebook dilemma presentation
 
Six Sigma By Mhussain
Six Sigma By MhussainSix Sigma By Mhussain
Six Sigma By Mhussain
 
20070502 takaful malaysia
20070502 takaful malaysia20070502 takaful malaysia
20070502 takaful malaysia
 
Taxation implications for company paid healthcare for large employers
Taxation implications for company paid healthcare for large employersTaxation implications for company paid healthcare for large employers
Taxation implications for company paid healthcare for large employers
 
Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013
 
Build desktop app_by_xulrunner
Build desktop app_by_xulrunnerBuild desktop app_by_xulrunner
Build desktop app_by_xulrunner
 
Wellbeing strategies in the workplace
Wellbeing strategies in the workplaceWellbeing strategies in the workplace
Wellbeing strategies in the workplace
 
改善Programmer生活的sql技能
改善Programmer生活的sql技能改善Programmer生活的sql技能
改善Programmer生活的sql技能
 
Simplyhealth's Annual Dental Survey 2011
Simplyhealth's Annual Dental Survey 2011Simplyhealth's Annual Dental Survey 2011
Simplyhealth's Annual Dental Survey 2011
 
Plugin-able POS Solutions by Javascript @HDM9 Taiwan
Plugin-able POS Solutions by Javascript @HDM9 TaiwanPlugin-able POS Solutions by Javascript @HDM9 Taiwan
Plugin-able POS Solutions by Javascript @HDM9 Taiwan
 
Personal Skills
Personal SkillsPersonal Skills
Personal Skills
 
20070502 takaful malaysia
20070502 takaful malaysia20070502 takaful malaysia
20070502 takaful malaysia
 
Use of Replication and Portable Hardness Testing for High Temperature Plant I...
Use of Replication and Portable Hardness Testing for High Temperature Plant I...Use of Replication and Portable Hardness Testing for High Temperature Plant I...
Use of Replication and Portable Hardness Testing for High Temperature Plant I...
 
Personal Skills
Personal SkillsPersonal Skills
Personal Skills
 
Pakistan Telecommunication Services
Pakistan Telecommunication ServicesPakistan Telecommunication Services
Pakistan Telecommunication Services
 

Ähnlich wie Phalcon phpconftw2012

ColaPHP In Action
ColaPHP In ActionColaPHP In Action
ColaPHP In Actionfuchaoqun
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和javasulong
 
Lamp高性能设计
Lamp高性能设计Lamp高性能设计
Lamp高性能设计锐 张
 
Symfony簡介
Symfony簡介Symfony簡介
Symfony簡介Ricky Su
 
Phalcon2014 Startup
Phalcon2014 StartupPhalcon2014 Startup
Phalcon2014 StartupSteve Luo
 
2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swt2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swttka
 
LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 CAVEDU Education
 
lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用hugo
 
千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7javatwo2011
 
PHP & AppServ
PHP & AppServPHP & AppServ
PHP & AppServHt Wang
 
Javascript primer plus
Javascript primer plusJavascript primer plus
Javascript primer plusDongxu Yao
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨Wen-Tien Chang
 
常用开发工具介绍
常用开发工具介绍常用开发工具介绍
常用开发工具介绍haozes
 
Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterBo-Yi Wu
 
使用Lua提高开发效率
使用Lua提高开发效率使用Lua提高开发效率
使用Lua提高开发效率gowell
 
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案LaravelConfTaiwan
 
做自己的可可豆夾 @ cocoahead.tw
做自己的可可豆夾 @ cocoahead.tw做自己的可可豆夾 @ cocoahead.tw
做自己的可可豆夾 @ cocoahead.twKai-Yuan Cheng
 
互联网创业服务器运维工具集
互联网创业服务器运维工具集互联网创业服务器运维工具集
互联网创业服务器运维工具集zhen chen
 

Ähnlich wie Phalcon phpconftw2012 (20)

ColaPHP In Action
ColaPHP In ActionColaPHP In Action
ColaPHP In Action
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和java
 
Lamp高性能设计
Lamp高性能设计Lamp高性能设计
Lamp高性能设计
 
工作坊簡介
工作坊簡介工作坊簡介
工作坊簡介
 
Symfony簡介
Symfony簡介Symfony簡介
Symfony簡介
 
Phalcon2014 Startup
Phalcon2014 StartupPhalcon2014 Startup
Phalcon2014 Startup
 
2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swt2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swt
 
LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697
 
AMF
AMFAMF
AMF
 
lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用
 
千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7
 
PHP & AppServ
PHP & AppServPHP & AppServ
PHP & AppServ
 
Javascript primer plus
Javascript primer plusJavascript primer plus
Javascript primer plus
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨
 
常用开发工具介绍
常用开发工具介绍常用开发工具介绍
常用开发工具介绍
 
Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniter
 
使用Lua提高开发效率
使用Lua提高开发效率使用Lua提高开发效率
使用Lua提高开发效率
 
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
 
做自己的可可豆夾 @ cocoahead.tw
做自己的可可豆夾 @ cocoahead.tw做自己的可可豆夾 @ cocoahead.tw
做自己的可可豆夾 @ cocoahead.tw
 
互联网创业服务器运维工具集
互联网创业服务器运维工具集互联网创业服务器运维工具集
互联网创业服务器运维工具集
 

Phalcon phpconftw2012

  • 1. Phalcon  PHP  Framework   The  Fastest  Faster  PHP  Framework 阿土伯
  • 2. about:me !   目前為 ViViPOS  Co.,  Ltd  技術總監   !   利用 javascript  寫 〞收銀機〞(傳統產業,全新感受)   ! CoCo  都可、50嵐、歇腳亭、Yamaha  、星聚點  KTV     !   #3  commiHer  of  cphalcon  repository   !   PHP  /  Javascript  /  Java  Programmer  (目前移情於 Scala  )   ! racklin@gmail.com   ! hHps://twiHer.com/racklin   ! hHps://www.facebook.com/racklin1002   ! hHp://racklin.blogspot.tw/      (生小孩後就變癈墟)  
  • 3. 議題 ! PhalconPHP  Framework 介紹   ! PhalconPHP  Kernel 介紹   !   DEMO  c9s  ValidaWonKit  porWng  as  php  extension  
  • 4. Programmers  共同的罩門   !  速度最快!   !  使用資源最小!   !  跨平台!    
  • 5. Programmers  共同的罩門   !  速度最快!   !  使用資源最小!   !  跨平台!       所以大家來聽 PhalconPHP  
  • 6. 為什麼快 !   Fibonacci  40  (費式數列)  hHp://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
  • 7. Fibonacci  40 500   400   300   200   100   0   c  with  -­‐ java   scala   nodejs   ruby   php  5.4   ruby   php  5.3   O2   1.9.2   1.8.x  
  • 8. 所以結論…   下一個專案要用 c  /  c++  來寫  web    
  • 9. Raphters !   A  web  framework  for  C
  • 10. WOW!  COOOOOOL~ 看起來好像很容易!
  • 11. 除了慣C哥     大部份人打完招呼不知道要做什麼…..
  • 13. Fibonacci  as  php  extension
  • 14. Fibonacci  as  php  extension 0m0.79s        馬上變成第二名
  • 15. Fibonacci  圖表 450   400   350   300   250   200   150   100   50   0   c  with  -­‐O2   java   scala   nodejs   ruby  1.9.2   5.4   php   ruby  1.8.x   5.3  php  ext   php  
  • 17. 漂亮的平衡   A  PHP  web  framework     delivered  as  a  C  extension
  • 18. PHP  extension  frameworks   PhalconPHP   Yaf
  • 19. 為什麼不是 Yaf !   Underscore  Class  Name  (  目標 PHP  5.2 和以上版本)   !   Document 實在不多   !   Sample  Codes    更少    
  • 20. 為什麼不是 Yaf !   Underscore  Class  Name  ( 目標 PHP  5.2 和以上版本)   !   Document 實在不多   !   Sample  Codes    更少     !   Yet  Another  Framework  (Yaf)     這專案名稱我不喜歡   很怕將來會出一個  What  The  Framework  (WTx)  
  • 23. PhalconPHP  benefits !   PHP  Extension  –  Faster   ! Phalcon  all  Components  are  loosely  coupled   !   Low-­‐Level  OpWmizaWons   !   Using  c-­‐language  ORM  for  PHP   !   PHQL  –  lemon  parser  (SQLite)   !   Well-­‐documented  
  • 24. PhalconPHP  0.5  news !   Namespaces   !   Class  Loader  –  相容於 PSR-­‐0   !   Dependency  Injec8on   !   Events  Manager   !   PDO  Database  Adapters   !   *  支援 SQLite.       !   *  PostgreSQL  支援 Mul8-­‐Schemas   !   *  CLI  Applica8ons   !   Micro  Applica8ons   !   Full  stack  frameworks  
  • 25. PhalconPHP  0.6 !   Object-­‐Document  Mapper  -­‐  MongoDB   !   Volt:  Template  Engine    -­‐  inspired  on  Twig   !   PS.  11/2  Released  
  • 26. Class  Loader   Dependency  InjecWon   Events  Manager       Flexible   Extensible   Plugin-­‐able    
  • 27. Class  Loader !   盡可能不用使用 include  /  require  .   ! registerNamespaces  –  PSR-­‐0  相容   ! registerPrefixes   ! registerClasses   ! registerDirectories  
  • 29. Composer •  類似 PEAR  的套件管理工具,但更方便! 像是 npm  /  brew  。   •  Install  Composer   $  curl  -­‐s  hHps://getcomposer.org/installer  |  php •  IniWal  project   $  composer.phar  init •  Require  /  Install  libraries   $  composer.phar  require  [vendor/name] •  Update  libraries   $  composer.phar  update
  • 30. Composer  Autoloading •  只要加一行在你的程式中   require  'vendor/autoload.php'; hHps://packagist.org/
  • 31. Phalcon  Class  Loader  +     Composer  Autloading ! Phalcon  and  Composer  都是使用 spl_autoload_register  ,   spl_autoload_register 相當聰明,載入類別後會中斷執行, 不會重覆載入   !   註冊 多個 autoload  handlers  是安全的         !   所以只要在 Phalcon  Class  Loader  前先加上一行即可     require  'vendor/autoload.php’;  
  • 32. Dependency  InjecWon !   PhalconDI  實作了 IoC  設計模式,幫助寫出可擴充性、易 於測試、維護的程式碼。   ! PhalconPHP  內部大量利用 DI  將各元件串接起來。    
  • 33. Dependency  InjecWon !   產生新的物件或單例(Singleton) - get  /  getShared   !   傳參數給  Constructor   !   Lazy  loading   !   物件只有在被取得時才會產生   !   Magic     !   如果沒有註冊,會自動試著找同樣的 Class  Name   !   如果可以,全部利用 DI  來產生您的類別實例。
  • 35. DI  範例  (get) !   取得物件   $request  =  $di-­‐>get("request");   !   透過 magic  method   $request  =  $di-­‐>getRequest();   !   Singleton   $request  =  $di-­‐>getShared("request");   !   傳參數給 constructor   $component  =  $di-­‐>get("MyComponent",  array("some-­‐ parameter",  "other"))
  • 36. Events  Manager !   Web  GUI  程式中,我們大量使用 Events 。   !   DOM  Events   !   Events  Manager  -­‐  fire  event  ,  aHach  listener   !   Event  Type  Using  colon  :  as  namespace  separator.    
  • 37. DEMO !   Using  Class  Loader    /  Dependency  InjecWon  /  Events  Manager   for  plugin-­‐able  applicaWons.   !   Linux  Upstart  init  daemon  like  demo   hHp://upstart.ubuntu.com/    (replacement  for  the  venerable   System-­‐V  init)   !   Shopping-­‐Cart  Plugin-­‐able  PromoWons  .  
  • 38. Micro  Framework !   Simple  and  ResTul   !   Frameworks   ! RubyàSinatra,  Cuba ! PythonàFlask,  Pyramid   !   PHP  àSilex,  Slim   !   Java  àNapalm  
  • 40. Full  Stack  Framework !   MVC  Architecture   !   Router  /  Dispatcher   !   View  Helper  /  Template  Engine   !   Filtering  Data   !   Session     !   Cache   !   ACL   !   Logging   !   I18n/l10n  
  • 41. Models CreaWng  Models By  default  model  “Robots”  will  refer  to  the  table  “robots”.
  • 44. Models Finding  with  condiWons  ,  order  and  Limit
  • 48. Models  -­‐  Criteria !   Similar  To     !   Doctrine  QueryBuilder   ! Yii  Query  Object   !   Provides  a  fluent  API.  
  • 49. PHQL !   Similar  To     !   Doctrine  DQL   !   Hibernate  HQL   ! Phalcon  Query  Language  is  a  high  level,  object  oriented  SQL   dialect.   !   High  performance,  Phalcon  provides  a  parser  that  uses  the   same  technology  as  SQLite.  (lemon  parser)   hHp://www.sqlite.org/src/doc/trunk/doc/lemon.html  
  • 52. View  Helpers !   WriWng  and  maintaining  HTML  markup  can  quickly Document  type Produced
  • 53. Template  Engine  -­‐  Volt !   Volt  is  an  ultra-­‐fast  and  designer  friendly  templaWng  language   wriHen  in  C  ,  inspired  on  Twig.
  • 54. Console  ApplicaWon !   CLI  Components   ! cronjobs   !   Daemon  ApplicaWon   !   Long-­‐life  applicaWon  ,  using  supervisor  and  kill  yourself.   !   Job  Workers   !   Using  supervisor  and  kill  yourself.    
  • 56. CLI  MainTask Php  console.php    //  MainTask::mainAcWon   Php  console.php  main  test  //  MainTask::testAcWon  
  • 58. PhalconPHP  Kernel ! hHps://github.com/racklin/phalcon_kernel   !   由 cphalcon  中抽離出來的專案。   !   提供大量基於 Zend  API  的巨集/工具。   !   簡化 php  extension  開發。  
  • 59. Why  Extension !   Driver  /  Adapter   !   Low-­‐level  NaWve  Code  Libraries   !   Performance   !   EncapsulaWon  /  InformaWon  Hidden   !   For  Developer   !   For  Customers    
  • 60. zval
  • 61. c:  zval  *a       相當於   php:  $a
  • 62. Data  Types Create  macro Long Boolean Double String  value ZVAL_LONG() ZVAL_BOOL() ZVAL_DOUBLE() ZVAL_STRING() NULL ZVAL_NULL()
  • 63. Data  Types GeHer  and  IdenWfy  macro 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() Iden8fy   BOOL Long Double String NULL Z_TYPE() IS_BOOL IS_LONG IS_DOUBLE IS_STRING IS_NULL Z_TYPE_P()
  • 64. Return  Types Macro Type RETURN_FALSE  /  RETURN_TRUE Boolean RETURN_NULL() NULL RETURN_LONG() Long RETURN_DOUBLE() Double RETURN_STRING() String RETURN_CTOR()   ZVAL  (Phalcon) RETURN_CCTOR()   RETURN_NCTOR()
  • 65. Memory  Management ! Phalcon  Memory  Management  簡化了 Zend  Memory   Managemant.   !   PHALCON_MM_GROW()   建立一個 phalcon  memory  entry  結構   !   PHALCON_INIT_VAR  /  PHALCON_ALLOC_ZVAL_MM     建立並配置記憶體給 zval   並將其設為 null,  且將其指標的指 標存至 phalcon  memory  entry.   !   PHALCON_MM_RESTORE   釋放所有經由 PHALCON_INIT_VAR  配置且 refcount  =1  的記 憶體
  • 66. Phalcon  MM  Bad  Parts !   PHALCON_ALLOC_ZVAL_MM  or  PHALCON_INIT_VAR   !   如果你 trace  source  code  二者差別只在於一個是先將 zval   pointer  pointer  放入 memory  entry  再設定初始值。一個是先設 定初始值再將 zval  pointer  pointer  放入 memory  entry  ….     !   PHALCON_INIT_VAR  3488  lines   !   PHALCON_ALLOC_ZVAL_MM      468  lines    
  • 68. String !   ZVAL_STRING()  –  Zend  API   PHALCON_INIT_VAR(month);       ZVAL_STRING(month,  "2012",  1);   PHALCON_INIT_VAR(today_is);         ZVAL_STRING(today_is,  "Today  is",  1); ! concat_funcWon  –  Zend  API   PHALCON_INIT_VAR(first_part);   concat_funcWon(first_part,  today_is,  month); ! Concat  macro   PHALCON_INIT_VAR(today);     PHALCON_CONCAT_SVSV(today,  "Today  is",  month,  "  ",  day);  
  • 69. 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)  
  • 70. Arrays !    array_init(zval*)  –  iniWal  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  
  • 71. Phalcon  Arrays  Bad  Parts !   PHP  String  is  Binary-­‐Safe   !   String  Length  =  Actually  String  Length   !   String  Size  =  String  Length  +  1  bytes(0)   !   Arrays  fetch  and  update  using  String  Length   !   Arrays  isset  and  unset  using  String  Size   ! Phalcon_array_unset  not  phalcon_array_unset_long
  • 72. Call  FuncWons !   PHALCON_CALL_FUNC     呼叫 PHP  funcWon  ,有回傳值   !   PHALCON_CALL_FUNC_NORETURN   呼叫 PHP  funcWon  ,沒有回傳值 !   PHALCON_CALL_FUNC_PARAMS_1     呼叫 PHP  funcWon 並傳一個參數,有回傳值   !   PHALCON_CALL_FUNC_PARAMS_1_NORETURN   呼叫 PHP  funcWon 並傳一個參數,沒有回傳值   !   目前巨集定義到傳 3 個參數  
  • 73. Call  FuncWons PHP  Code
  • 75. Call  Methods !   PHALCON_CALL_METHOD   呼叫 PHP  funcWon ,有回傳值   !   PHALCON_CALL_METHOD_NORETURN   呼叫 PHP  funcWon ,沒有回傳值 !   PHALCON_CALL_METHOD_PARAMS_1     呼叫 PHP  funcWon 並傳一個參數,有回傳值   !   PHALCON_CALL_METHOD_PARAMS_1_NORETURN   呼叫 PHP  funcWon 並傳一個參數,沒有回傳值   !   目前巨集定義到傳 5  個參數  
  • 77. Object  ProperWes !   Update  Property   !    phalcon_update_property_long   !    phalcon_update_property_bool   !    phalcon_update_property_null   !    phalcon_update_property_zval  /   phalcon_update_property_zval_zval   !   Read  Property   !    phalcon_read_property  /  phalcon_read_property_zval   ! Isset  Property   !    phalcon_isset_property  /  phalcon_isset_property_zval  
  • 78. PHP  Style WriWng  c  extension
  • 80. References !   Slide:   hHps://speakerdeck.com/racklin/phalcon-­‐php-­‐framework-­‐and-­‐ phalcon-­‐kernel-­‐introducWon-­‐phpcon€w2012   !   Sample  code:   hHps://github.com/racklin/phpcon€w2012_phalcon   ! PhalconPHP  internal:     hHp://internals.phalconphp.com/en/latest/index.html