Upgrade to Pro — share decks privately, control downloads, hide ads and more …

(phpconftw2012) PHP as a Middleware in Embedded...

Avatar for sosorry sosorry
November 13, 2012

(phpconftw2012) PHP as a Middleware in Embedded Systems

It is used by sosorry at PHPConf Taiwan 2012. In this presentation, we will see that why we need a middleware in embedded systems, and how PHP can play this role. Besides, some tasks about architecture design, porting libraries, development & debug, and performance tunning would be included.

Avatar for sosorry

sosorry

November 13, 2012

Other Decks in Programming

Transcript

  1. • Request the developer account to 3rd party • Get

    the technical document • Build the test environment • Download sample code • Test all APIs with JAVA • … OK
  2. An embedded system is a computer system designed for specific

    control functions within a larger system, often with real-time computing constraints. Embedded System
  3. • No APT, no YUM • Hardware limitation • !

    Scale • Deploy/update not easy
  4. • RESTFul API • JSON/XML data format • Symmetric/asymmetric encryption

    • SSL communication • Data storage • Multi-byte encoding
  5. • Tiny, low resource usage • Community contribution (PEAR/PECL) •

    3rd party API (Youtube/Twitter/Facebook...) • Integration with lots of libraries
  6. • 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
  7. • Apache MPM prefork + mod_php • Nginx + FastCGI

    • Lighttpd + PHP-FPM • Boa + PHP-CGI
  8. • Shared library • Embedded build (--enable-embed) • Shell command

    • Socket PHP Native Code data exchange invoke
  9. • Concurrent server (No multi-thread in PHP) • IPC mechanism

    (broadcast/multicast/unicast) • Client/Server command protocol • No framework, all things handmade Design
  10. • Prepare toolchain • Configure with minimized features • Resolve

    dependency & version conflict • Resolve compilation error • Test all functions in the target machine • Reduce library size
  11. • Ubuntu /OS • Vim & plugin /editor • Shell

    script /automation tool • Meld /visual diff and merge tool • SVN /version control system • Jira /bug tracking system Development Environment
  12. • print_r(), var_dump() • Xdebug & xdebug_debug_zval() • log_errors &

    error_log in php.ini • debugging level in config.ini Console Debug
  13. • Set breakpoint • Step into/step over/step out • Watch

    variables • Display call stack IDE Debug
  14. • 買好一點的硬體 • 優化 SQL 語法 • 關掉同步 commit •

    增加寫入 buffer 的大小 • 增加 wait write 的 delay time • … 等等 常見招數
  15. • --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 Write an Extension
  16. • Change debugging level during runtime • Dump debug information

    to a specific usb drive • inotify + blkid Extension for Debugging