SlideShare a Scribd company logo
1 of 91
Download to read offline
PHP as a Middleware
in Embedded Systems
    @phpconftw2012
Hi, I'm sosorry
不可能的電視
系統廠工程師
本次分享
僅代表個人意見
不代表公司立場
故事開始
2012 年 , 連網電視正夯
老闆想在電視上新增一個網路 App
該如何開始?
先來測個 API 吧
●
    Request the developer account to 3rd party
●   Get the technical document
●   Build the test environment
●   Download sample code
●   Test all APIs with JAVA
●   … OK
杯具發生了 ...
板子上沒有 JVM
歡迎來到嵌入式系統的世界
Embedded System

An embedded system is a computer system
designed for specific control functions within a
larger system, often with real-time computing
constraints.
●   No APT, no YUM
●   Hardware limitation
●   ! Scale
●   Deploy/update not easy
Back to the basics
Q1:
app 在嵌入式系統是如何顯示的?
Display System


   Application



   GUI-ToolKit


   Framebuffer


    Hardware
In Embedded System




     /dev/fb driver


         SoC
application 受限於 GUI-Toolkit
Q2:
是否可以讓 UI 只做 UI ?
Software Glue




source: http://www.furniturefromturkey.com/
Middleware

  Application




 Turnkey/Driver

   Hardware
Middleware

  Application




 Turnkey/Driver

   Hardware
Middleware

  Application



    interface




    interface
 Turnkey/Driver

   Hardware
Middleware

   Application



     interface

Portable Layer
     interface
  Turnkey/Driver

    Hardware
Q3:
      rd
要能實做 3 Party App 的基本需求?
●   RESTFul API
●   JSON/XML data format
●   Symmetric/asymmetric encryption
●   SSL communication
●   Data storage
●   Multi-byte encoding
PHP as Software Glue
in Embedded Systems
Why PHP
●   Tiny, low resource usage
●   Community contribution (PEAR/PECL)
●   3rd party API (Youtube/Twitter/Facebook...)
●   Integration with lots of libraries
●   RESTFul API /cURL
●   JSON/XML data format /LibeXpat, Libxml2
●   Symmetric/asymmetric encryption /Libmcrypt
●   SSL communication /OpenSSL
●   Data storage /SQLite3
●   Multi-byte encoding /Libiconv
●   Inter-Process Communication /Socket, SHM
●   Core /PHP-CLI
PHP as a Middleware

      Application




     Turnkey/Driver

       Hardware
Tasks
●   Architecture design
●   Porting libraries
●   Development & debug
●   Performance tunning
Architecture Design
Web Server + PHP ?
●   Apache MPM prefork + mod_php
●   Nginx + FastCGI
●   Lighttpd + PHP-FPM
●   Boa + PHP-CGI
杯具又發生了 ...
●
  資源吃很兇
● 不容易移植

●
  記憶體洩漏
●
  常常連不上
砍掉重練
PHP Inter-Process Communication
PHP

invoke   data exchange

Native Code
●   Shared library




                         PHP

                     invoke   data exchange

                     Native Code
●   Shared library
●   Embedded build (--enable-embed)



                                      PHP

                                  invoke   data exchange

                                  Native Code
●   Shared library
●   Embedded build (--enable-embed)
●   Shell command

                                      PHP

                                  invoke   data exchange

                                  Native Code
●   Shared library
●   Embedded build (--enable-embed)
●   Shell command
●   Socket
                                      PHP

                                  invoke   data exchange

                                  Native Code
Socket Server
Design
●   Concurrent server (No multi-thread in PHP)
●   IPC mechanism (broadcast/multicast/unicast)
●   Client/Server command protocol
●   No framework, all things handmade
PHP Work Flow
Turnkey/Driver

  Hardware
application interface

socket server           storage

       Turnkey/Driver

         Hardware
application interface

socket server           storage

       Turnkey/Driver

         Hardware
application interface

socket server           storage

       Turnkey/Driver

         Hardware
You Tube   application interface

           socket server           storage

                  Turnkey/Driver

                    Hardware
You Tube   application interface

Pandora    socket server           storage

                  Turnkey/Driver

                    Hardware
You Tube   application interface

Pandora    socket server           storage

Twitter           Turnkey/Driver

                    Hardware
You Tube   application interface

Pandora    socket server           storage

Twitter           Turnkey/Driver

                    Hardware
You Tube   application interface

Pandora    socket server           storage

Twitter           Turnkey/Driver

                    Hardware
Porting Libraries
●   Prepare toolchain
●   Configure with minimized features
●   Resolve dependency & version conflict
●   Resolve compilation error
●   Test all functions in the target machine
●   Reduce library size
Development & Debug
Development Environment
●   Ubuntu /OS
●   Vim & plugin /editor
●   Shell script /automation tool
●   Meld /visual diff and merge tool
●   SVN /version control system
●   Jira /bug tracking system
Console Debug
●   print_r(), var_dump()
●   Xdebug & xdebug_debug_zval()
●   log_errors & error_log in php.ini
●   debugging level in config.ini
IDE Debug
●   Set breakpoint
●   Step into/step over/step out
●   Watch variables
●   Display call stack
Performance Tunning
Profiling
●   Xdebug
●   Kcachegrind
●   VLD (Vulcan Logic Disassembler)
Xdebug
●   Stack/function traces
●   Code coverage analysis
●   Time tracking
●   Memory usage
tracefile-analyser
●   Aggregate information from xdebug
●   Sort by time/memory/calls
Kcachegrind
●   Analyze xdebug profiling data
●   Call graph viewer(callers/callees)
VLD
●   An opcode dumper
A simple comparison
array_push
array assignment
# of Opcodes = 16
# of Opcodes = 10
Tunning
Alternative PHP Cache (APC)




source: http://www.slideshare.net/shire/php-tek-2008-apc-facebook
DB is always the bottleneck
常見招數
●
    買好一點的硬體
●   優化 SQL 語法
●   關掉同步 commit
●   增加寫入 buffer 的大小
●   增加 wait write 的 delay time
●
    … 等等
SQLite3 Tunning
●   Configuration
    ●   SQLITE_MAX_LENGTH=2147483647
    ●   SQLITE_MAX_SQL_LENGTH=1073741824

●   lock/unlock
    ●   $handle->busyTimeout($time)

●   Single statement
    ●   Concat SQL string
    ●   Begin; SQL; Commit;
Write an Extension
●   --enable-debug --enable-maintainer-zts
●   ext_skel
      $ vi ext/$extname/config.m4
      $ ./buildconf
      $ ./configure –[with|enable]-$extname
      $ make
      $ ./php -f ext/$extname/$extname.php
      $ vi ext/$extname/$extname.c
      $ make
Extension for Debugging
●   Change debugging level during runtime
●   Dump debug information to a specific usb drive
●   inotify + blkid
Integration
這又是另外一個故事了
Thanks
Special Thanks
●   Jeffrey Chen
●   Simon Wang
Q &A

More Related Content

What's hot

The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
Oleg Podsechin
 
Las16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - statusLas16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - status
Linaro
 
Php under the_hood
Php under the_hoodPhp under the_hood
Php under the_hood
frank_neff
 
蔡学镛 Rebol漫谈
蔡学镛   Rebol漫谈蔡学镛   Rebol漫谈
蔡学镛 Rebol漫谈
d0nn9n
 

What's hot (20)

Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
 
Php’s guts
Php’s gutsPhp’s guts
Php’s guts
 
IncludeOS for ics 2018
IncludeOS for ics 2018IncludeOS for ics 2018
IncludeOS for ics 2018
 
Las16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - statusLas16 309 - lua jit arm64 port - status
Las16 309 - lua jit arm64 port - status
 
Composer Helpdesk
Composer HelpdeskComposer Helpdesk
Composer Helpdesk
 
Virtualizing Development
Virtualizing DevelopmentVirtualizing Development
Virtualizing Development
 
このPHP拡張がすごい!2017
このPHP拡張がすごい!2017このPHP拡張がすごい!2017
このPHP拡張がすごい!2017
 
“Bootify your app - from zero to hero
“Bootify  your app - from zero to hero“Bootify  your app - from zero to hero
“Bootify your app - from zero to hero
 
Livecode widget course
Livecode widget courseLivecode widget course
Livecode widget course
 
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
 
PHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLiPHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLi
 
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
 
Php under the_hood
Php under the_hoodPhp under the_hood
Php under the_hood
 
蔡学镛 Rebol漫谈
蔡学镛   Rebol漫谈蔡学镛   Rebol漫谈
蔡学镛 Rebol漫谈
 
Composer
ComposerComposer
Composer
 
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
 
Embedded Linux - Building toolchain
Embedded Linux - Building toolchainEmbedded Linux - Building toolchain
Embedded Linux - Building toolchain
 

Similar to (phpconftw2012) PHP as a Middleware in Embedded Systems

Php Inside - confoo 2011 - Derick Rethans
Php Inside -  confoo 2011 - Derick RethansPhp Inside -  confoo 2011 - Derick Rethans
Php Inside - confoo 2011 - Derick Rethans
Bachkoutou Toutou
 
Dutch php conference_2010_opm
Dutch php conference_2010_opmDutch php conference_2010_opm
Dutch php conference_2010_opm
isnull
 

Similar to (phpconftw2012) PHP as a Middleware in Embedded Systems (20)

Php Inside - confoo 2011 - Derick Rethans
Php Inside -  confoo 2011 - Derick RethansPhp Inside -  confoo 2011 - Derick Rethans
Php Inside - confoo 2011 - Derick Rethans
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
TSC Summit #3 - Reverse engineering and anti debugging techniques
TSC Summit #3 - Reverse engineering and anti debugging techniquesTSC Summit #3 - Reverse engineering and anti debugging techniques
TSC Summit #3 - Reverse engineering and anti debugging techniques
 
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
Hyperion EPM APIs - Added value from HFM, Workspace, FDM, Smartview, and Shar...
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
 
Joomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation TestingJoomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation Testing
 
Dutch php conference_2010_opm
Dutch php conference_2010_opmDutch php conference_2010_opm
Dutch php conference_2010_opm
 
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
 
OpenShift Origin Community Day (Boston) Extending OpenShift Origin: Build You...
OpenShift Origin Community Day (Boston) Extending OpenShift Origin: Build You...OpenShift Origin Community Day (Boston) Extending OpenShift Origin: Build You...
OpenShift Origin Community Day (Boston) Extending OpenShift Origin: Build You...
 
C++ Programming and the Persistent Memory Developers Kit
C++ Programming and the Persistent Memory Developers KitC++ Programming and the Persistent Memory Developers Kit
C++ Programming and the Persistent Memory Developers Kit
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Owasp AppSecEU 2015 - BeEF Session
Owasp AppSecEU 2015 - BeEF SessionOwasp AppSecEU 2015 - BeEF Session
Owasp AppSecEU 2015 - BeEF Session
 
Monkey Server
Monkey ServerMonkey Server
Monkey Server
 
Nodejs
NodejsNodejs
Nodejs
 
NodeJS
NodeJSNodeJS
NodeJS
 
Zend Products and PHP for IBMi
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi
 
Devops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftDevops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShift
 

Recently uploaded

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 

Recently uploaded (20)

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 

(phpconftw2012) PHP as a Middleware in Embedded Systems