SlideShare a Scribd company logo
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
(phpconftw2012) PHP as a Middleware in Embedded Systems
Performance Tunning
Profiling
●   Xdebug
●   Kcachegrind
●   VLD (Vulcan Logic Disassembler)
Xdebug
●   Stack/function traces
●   Code coverage analysis
●   Time tracking
●   Memory usage
(phpconftw2012) PHP as a Middleware in Embedded Systems
tracefile-analyser
●   Aggregate information from xdebug
●   Sort by time/memory/calls
(phpconftw2012) PHP as a Middleware in Embedded Systems
Kcachegrind
●   Analyze xdebug profiling data
●   Call graph viewer(callers/callees)
(phpconftw2012) PHP as a Middleware in Embedded Systems
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 (20)

PPTX
Performance tips for Symfony2 & PHP
Max Romanovsky
 
PPT
The future of server side JavaScript
Oleg Podsechin
 
PPTX
Taming the resource tiger
Elizabeth Smith
 
PDF
PHP, Under The Hood - DPC
Anthony Ferrara
 
PPTX
Php’s guts
Elizabeth Smith
 
PDF
IncludeOS for ics 2018
Per Buer
 
PDF
Las16 309 - lua jit arm64 port - status
Linaro
 
PDF
Composer Helpdesk
Sven Rautenberg
 
PDF
Virtualizing Development
Adam Culp
 
PDF
このPHP拡張がすごい!2017
sasezaki
 
PDF
“Bootify your app - from zero to hero
Izzet Mustafaiev
 
PDF
Livecode widget course
crazyaxe
 
PDF
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
Ortus Solutions, Corp
 
PDF
PHP & MySQL: PDO x MySQLi
Marcos Marcolin
 
PDF
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
GregMefford
 
PDF
Php under the_hood
frank_neff
 
PDF
蔡学镛 Rebol漫谈
d0nn9n
 
PDF
Composer
Le Thanh Sang
 
PDF
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Puppet
 
PDF
Embedded Linux - Building toolchain
Emertxe Information Technologies Pvt Ltd
 
Performance tips for Symfony2 & PHP
Max Romanovsky
 
The future of server side JavaScript
Oleg Podsechin
 
Taming the resource tiger
Elizabeth Smith
 
PHP, Under The Hood - DPC
Anthony Ferrara
 
Php’s guts
Elizabeth Smith
 
IncludeOS for ics 2018
Per Buer
 
Las16 309 - lua jit arm64 port - status
Linaro
 
Composer Helpdesk
Sven Rautenberg
 
Virtualizing Development
Adam Culp
 
このPHP拡張がすごい!2017
sasezaki
 
“Bootify your app - from zero to hero
Izzet Mustafaiev
 
Livecode widget course
crazyaxe
 
CBDW2014- Intro to CommandBox; The ColdFusion CLI, Package Manager, and REPL ...
Ortus Solutions, Corp
 
PHP & MySQL: PDO x MySQLi
Marcos Marcolin
 
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
GregMefford
 
Php under the_hood
frank_neff
 
蔡学镛 Rebol漫谈
d0nn9n
 
Composer
Le Thanh Sang
 
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Puppet
 
Embedded Linux - Building toolchain
Emertxe Information Technologies Pvt Ltd
 

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

PDF
Integrating PHP With System-i using Web Services
Ivo Jansch
 
PDF
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
Ford AntiTrust
 
PPTX
PHP Performance with APC + Memcached
Ford AntiTrust
 
PDF
PHP at Yahoo!
elliando dias
 
PDF
Professional PHP: an open-source alternative for enterprise development [Kort...
Combell NV
 
KEY
Profiling php applications
Justin Carmony
 
PPTX
Debugging with Zend Studio for Eclipse
OSSCube
 
PDF
Getting started with PHP on IBM i
COMMON Europe
 
PDF
Qcon
adityaagarwal
 
PDF
IBM IMPACT 2009 Conference Session 2078 - Extending and Integrating Popular P...
Robert Nicholson
 
PDF
Php Inside - confoo 2011 - Derick Rethans
Bachkoutou Toutou
 
PDF
509 512
Editor IJARCET
 
PPTX
How to Supercharge your PHP Web API
Aurimas Niekis
 
PDF
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
Benjamin Cabé
 
ZIP
Memcached, presented to LCA2010
Mark Atwood
 
PDF
Open source building blocks for the Internet of Things - Jfokus 2013
Benjamin Cabé
 
ODP
Modern Application Stacks
chartjes
 
PPT
slidesharenew1
truptitasol
 
PPT
sdfsdfsdf
truptitasol
 
PPT
sdfsdfsdf
truptitasol
 
Integrating PHP With System-i using Web Services
Ivo Jansch
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
Ford AntiTrust
 
PHP Performance with APC + Memcached
Ford AntiTrust
 
PHP at Yahoo!
elliando dias
 
Professional PHP: an open-source alternative for enterprise development [Kort...
Combell NV
 
Profiling php applications
Justin Carmony
 
Debugging with Zend Studio for Eclipse
OSSCube
 
Getting started with PHP on IBM i
COMMON Europe
 
IBM IMPACT 2009 Conference Session 2078 - Extending and Integrating Popular P...
Robert Nicholson
 
Php Inside - confoo 2011 - Derick Rethans
Bachkoutou Toutou
 
How to Supercharge your PHP Web API
Aurimas Niekis
 
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
Benjamin Cabé
 
Memcached, presented to LCA2010
Mark Atwood
 
Open source building blocks for the Internet of Things - Jfokus 2013
Benjamin Cabé
 
Modern Application Stacks
chartjes
 
slidesharenew1
truptitasol
 
sdfsdfsdf
truptitasol
 
sdfsdfsdf
truptitasol
 
Ad

Recently uploaded (20)

PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Ad

(phpconftw2012) PHP as a Middleware in Embedded Systems