Download - Andres Gutierrez
![Page 1: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/1.jpg)
Phalcon PHP Framework escrito como
extensión en C
![Page 2: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/2.jpg)
Objetivo • Construir un verdadero framework de alto
rendimiento para PHP que sea fácil de usar al mismo tiempo
• Facilitar y aumentar la escalabilidad de proyectos en PHP sin aumentar la complejidad
![Page 3: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/3.jpg)
¿Porqué? • El uso de framework se ha convertido en
obligatorio para el desarrollo PHP profesional
• Los frameworks ofrecen herramientas y facilidades que hacen que nuestro trabajo sea más divertido
![Page 4: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/4.jpg)
¿Cómo funciona PHP?
APC, Xcache, eAccelerator
Interpretar (ejecutar) el árbol construído (bytecode) (Zend Engine)
Revisar que el programa sea correcto a nivel sintácDco (LINT)
Construir árbol sintácDco (consume memoria)
![Page 5: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/5.jpg)
Rendimiento en frameworks tradicionales
• Muchos archivos con clases y funciones son leídos en cada petición, la continua lectura de disco puede impactar el rendimiento
• La totalidad del código proporcionada por estos frameworks es interpretada en cada petición
• El código de un framework permanece igual entre una petición y otra, ¿porqué cargarlo e interpretarlo una y otra vez?
![Page 6: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/6.jpg)
¿Cómo funcionan las extensiones de C?
1. Las extensiones de C se cargan una sola vez cuando inicia el servidor junto con PHP
2. La funcionalidad que provee las extensión está lista para usar desde cualquier archivo PHP
3. El código no se interpreta en las extensiones, porque las extensiones están compiladas para una plataforma específica
![Page 7: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/7.jpg)
No debes aprender C, se sigue programando en PHP!
![Page 8: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/8.jpg)
¿Qué ofrece Phalcon? • Es un framework por componentes y full stack
al tiempo, cualquier componente se puede usar sin depender de otros o desarrollar una aplicación completa con él
• Phalcon está directamente engranado con PHP accediendo directamente a sus recursos internos
• Generación de código, helpers, template engine, scaffolding, etc.
![Page 9: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/9.jpg)
Frameworks Tradicionales Phalcon
Interpretación de cientos ó miles de líneas en PHP
Sí No
Cargar docenas de archivos por petición
Sí No
Revisar la existencia de clases, funciones, variables cada vez, en cada petición
Sí No
Realizar optimizaciones de bajo nivel para ganar rendimiento
No Sí
¿Cómo Phalcon es más rápido con respecto a los frameworks tradicionales?
![Page 10: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/10.jpg)
Poca ayuda al programador
Rendimiento Mayor
Alta ayuda al programador
Rendimiento Menor
Alta ayuda al programador
Rendimiento Mayor
Ayuda/Rendimiento
![Page 11: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/11.jpg)
Las comparaciones son odiosas pero necesarias
![Page 12: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/12.jpg)
![Page 13: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/13.jpg)
MVC Benchmark
![Page 14: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/14.jpg)
Tiempo que tarda en iniciar el framework
Lógica de Aplicación (Hello!)
Tiempo que tarda en finalizar la peDción
¿Qué se mide con un “Hola Mundo”?
![Page 15: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/15.jpg)
• Sistema Operativo: Mac OS X Lion 10.7.4 Servidor Web: Apache httpd 2.2.22
• PHP: 5.3.15 + APC 3.1.13 (Without Xdebug) • CPU: 3.06 Ghz Intel Core 2 Duo • Memoria Principal: 4GB 1333 MHz DDR3 • Disco Duro: 500GB SCSI/SAS HDD
Entorno de Pruebas
![Page 16: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/16.jpg)
ab –n 1000 –c 5 http://localhost/bench/phalcon/say/hello
![Page 17: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/17.jpg)
[#] ab -‐n 1000 -‐c 5 http://localhost/bench/phalcon/?_url=say/hello This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Server Software: Apache/2.2.21 Server Hostname: localhost Server Port: 80 Document Path: /bench/phalcon/?_url=say/hello Document Length: 16 bytes Concurrency Level: 5 Time taken for tests: 0.402 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 187000 bytes HTML transferred: 16000 bytes Requests per second: 2489.26 [#/sec] (mean) Time per request: 2.009 [ms] (mean) Time per request: 0.402 [ms] (mean, across all concurrent requests) Transfer rate: 454.58 [Kbytes/sec] received Connection Times (ms) min mean[+/-‐sd] median max Connect: 0 0 0.3 0 4 Processing: 1 2 1.5 1 36 Waiting: 0 1 1.4 1 30 Total: 1 2 1.6 2 37 Percentage of the requests served within a certain time (ms) 50% 2 66% 2 75% 2 80% 2 90% 3 95% 4 98% 5 99% 7 100% 37 (longest request)
![Page 18: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/18.jpg)
Peticiones atendidas por segundo
0
500
1000
1500
2000
2500
280 324 424
568 541 727 762
862
2368
# PeDciones/sg
![Page 19: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/19.jpg)
Tiempo Promedio en las 1000 Peticiones
0
0,5
1
1,5
2
2,5
3
3,5 3,5
3
2,3
1,8 1,7
1,3 1,2 1,2
0,4
Tiempo Promedio sg
![Page 20: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/20.jpg)
Número de Archivos Interpretados por Petición
0
20
40
60
80
100
120 117
66
46 36
30 23
4
Número Archivos
![Page 21: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/21.jpg)
Memoria consumida por petición
0
0,5
1
1,5
2
2,5
3
3,5 3,5
3
1,75
1,25 1,1 1 0,75
Memoria (MB)
![Page 22: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/22.jpg)
mysql> desc products; +-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+ | Field | Type | Null | Key | Default | Extra | +-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | product_types_id | int(10) unsigned | NO | MUL | NULL | | | name | varchar(70) | NO | | NULL | | | price | decimal(16,2) | NO | | NULL | | | active | char(1) | YES | | NULL | | +-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐+-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐+ 5 rows in set (0.00 sec)
ORM Benchmark
![Page 23: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/23.jpg)
Inserción de 10 registros (Tiempo Total) 500 peticiones/10 concurrentes
0,000
1,000
2,000
3,000
4,000
5,000
6,000
Doctrine 2 Phalcon
5,922
2,375 Tiempo Total/sg
![Page 24: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/24.jpg)
Inserción de 10 registros (Memoria Petición) 500 peticiones/10 concurrentes
0,000
1,000
2,000
3,000
4,000
5,000
6,000
7,000
8,000
Doctrine 2 Phalcon
7,424
0,728
Memoria (MB)
![Page 25: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/25.jpg)
![Page 26: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/26.jpg)
Consultar e imprimir 10 registros (Tiempo Total) 500 peticiones/10 concurrentes
0,000
0,500
1,000
1,500
2,000
2,500
Doctrine 2 Phalcon
2,217
0,467
Tiempo/sg
![Page 27: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/27.jpg)
Consultar e imprimir 10 registros (Memoria Petición) 500 peticiones/10 concurrentes
0,000
1,000
2,000
3,000
4,000
5,000
6,000
7,000
8,000
9,000
10,000
Doctrine 2 Phalcon
9,984
0,768
Memoria (MB)
![Page 28: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/28.jpg)
Micro Framework: Peticiones atendidas por segundo
0
500
1000
1500
2000
2500
3000
Silex Slim Phalcon PHP
448
1134
2368 2551
# PeDciones/sg
![Page 29: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/29.jpg)
¿Es posible desarrollar una aplicación solamente usando Phalcon?
![Page 30: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/30.jpg)
• Full Stack Frameworks (Cake, Yii, Symfony, Zend)
• Componentes ligeramente acoplados (Symfony/Zend)
• Micro Frameworks (Slim, Silex, Limonade) • ORM (Object Relational Mappers) (Doctrine,
Propel) • ODM (Object Document Mappers) (Doctrine) • Template Engines (Twig, Mustache, Smarty)
Áreas de Acción
![Page 31: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/31.jpg)
1. Dependency Injection/Inversion of Control (DI) 2. HTTP Environment Request/Response 3. MVC (Models/Views/Controllers) 4. Cache (Memcached, Files, APC, Mongo) 5. Routing 6. Events Manager 7. Session Handling 8. Filter and Sanitize 9. Flash Notifications 10. Scaffolding 11. Configuration 12. Database 13. Logging 14. Template Engine (Volt) 15. Multi-lingual apps 16. Universal Class Loader 17. Access Control Lists (ACL)
Componentes
![Page 32: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/32.jpg)
• ORM (Object-Relational-Mapper) • Meta-Datos (Memoria, Sesión, APC, Files) • Validadores (Tipos, Regex, Únicos) • Relaciones Unidireccionales y Bidireccionales • Llaves foráneas virtuales • Transacciones • Generadores de Modelos • Eventos/Hooks de Modelos • Migraciones • PHQL (Phalcon Query Language) • Behaviors
Phalcon/ORM
![Page 33: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/33.jpg)
• MySQL • PostgreSQL • SQLite
Phalcon/DB
![Page 34: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/34.jpg)
Veamos un poco de código :]
![Page 35: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/35.jpg)
![Page 36: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/36.jpg)
![Page 37: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/37.jpg)
![Page 38: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/38.jpg)
![Page 39: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/39.jpg)
![Page 40: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/40.jpg)
Al estar escrito en C, ¿cómo encuentro fácilmente un error?
![Page 41: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/41.jpg)
![Page 42: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/42.jpg)
Implementaciones de PHP
96%
4%
Zend Engine
Hip Hop/Quercus/WebSmash/Phalanger
![Page 43: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/43.jpg)
Soy un programador perezoso, ¿Cómo Phalcon me ayuda a escribir
menos código?
![Page 44: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/44.jpg)
![Page 45: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/45.jpg)
![Page 46: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/46.jpg)
![Page 47: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/47.jpg)
![Page 48: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/48.jpg)
![Page 49: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/49.jpg)
![Page 50: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/50.jpg)
hhp://try.phalconphp.com
![Page 51: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/51.jpg)
![Page 52: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/52.jpg)
![Page 53: Andres Gutierrez](https://reader034.vdocuments.pub/reader034/viewer/2022050711/5487dfe6b4af9f6e0d8b557e/html5/thumbnails/53.jpg)
Gracias! <3
hhp://phalconphp.com
Síguenos en Twiher: @phalconphp