SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Welcome!


                PHP Inside

  ConFoo - Montréal, Canada - March 10th, 2011
Derick Rethans - derick@php.net - twitter: @derickr
             http://derickrethans.nl/talks.html
                     http://joind.in/2823
About Me



Derick Rethans




●   Dutchman living in London
●   PHP development
●   Author of the mcrypt, input_filter, dbus, translit
    and date/time extensions
●   Author of Xdebug
●   Contributor to the Apache Zeta Components
    Incubator project (formerly eZ Components)
●   Freelancer doing PHP (internals) development
PHP Inside
Am I mad?
My First Application

●   is the new hello world
●   Simple web API to get data
●   Authentication with HTTP basic auth
●   Simple interface: some buttons, an edit box and a
    list of tweets
GUI toolset

●   is a PHP binding for the GTK+ widget set
●   It comes as an extension for PHP
●   It wraps around many GTK+ widgets
●   GUI can be created from PHP:
 <?php
 $tb = new GtkToolbar();
 $tb->set_show_arrow( false );
 $tb->set_property( 'toolbar-style', Gtk::TOOLBAR_BOTH );
 $tb->set_property( 'icon-size', 6 );
 $this->updatebutton = GtkToolButton::new_from_stock( Gtk::STOCK_REFRESH );
 $lbl = new GtkLabel();
 $lbl->set_markup( '<span underline="single">U</span>pdate' );
 $this->updatebutton->set_label_widget( $lbl );
 $this->updatebutton->connect_simple( 'clicked', array( $this, 'update' ) );
 $this->updatebutton->add_accelerator( 'clicked', $accels, Gdk::KEY_U, Gdk::MOD1_MASK, 0 );
 $this->updatebutton->set_use_underline( true );
 $tb->insert( $this->updatebutton, -1 );
Getting PHP on the device

● It's an ARM processor
● Cross compiling vs compiling on the device


Cross-compiling:
● Requires cross-compilation set-up

● Tricky, and caused libtool problems for me


Compiling on the device
● All packages need to be found and installed

● Compiling PHP is really slow, you really don't


  want to use make clean
Data Storage

●   You can't really run a database server on the
    phone
●   SQLite is part of PHP, and self-contained
●   Indexes are vital on this platform
●   Clever use of SQL/Data manipulation is required
    for performance
Twitter App Experiences

●   Starting the app is not fast
●   Styling with GTK is tricky, especially if you want
    to run the app on the desktop too
●   Twitter API is very unstable, and inaccessible at
    times; it's also badly designed
●   You pull in way too much data than you need
●   My fingers are really fat
●   Can't really have the app running for a long time
Twitter Client: The Result
Tube Status
Transport for London

●   Provides status updates through
●   If you're traveling, it's really handy to have this
    information with you
●   There is no API, so you need to scrape
●   Widget provided for embedding:
●   Strict rules about colours etc.:




●   It's probably not totally legal
Scraping the Tube status

●   It's a ~25kb download; with GPRS the download
    time is about 5 seconds
●   It has lots of mark-up and JavaScript that we're
    not interested in
●   Using PHP to get the data we want from it is
    relatively slow
●   If the format changes, all the installed apps need
    to be updated
Web API

●    The download with status is only 0.5kb
●    The API caches the download
●    It only provides the data in JSON that we require:
 {
     "date":1273835118,
     "status":[
         ["Bakerloo",["Good service",""]],["Central",["Good service",""]],
         ["Circle",["Good service",""]],["District",["Good service",""]],
         ["H'smith & City",["Good service",""]],["Jubilee",["Good service",""]],
         ["Metropolitan",["Good service",""]],["Northern",["Good service",""]],
         ["Piccadilly",["Good service",""]],["Victoria",["Good service",""]],
         ["Waterloo & City",["Good service",""]]
     ]
 }

●    Parsing the JSON is fast, very little processing
     needed in the app, just display
●    If the HTML changes, only the scraping algorithm
     needs to be changed
Tube Status: The Result
Talking to the hardware

●   Many applications (phonebook, sending SMS) that
    came with the phone where suboptimal
●   Writing a new GUI is possible, but talking to the
    hardware requires D-BUS
●   D-BUS APIs are exposed by the freesmartphone
    project that the Linux distribution uses
●   PHP didn't have a D-BUS extension
PHP DBUS extension

●   DBUS bindings using the low-level C library
    (libdbus)
●   Provides proxy objects
●   Implements automatic-marshalling of data
●   Provides specific classes for full control
●   Support for method invocation, method calls,
    sending and receiving signals
●   (Basic) support for introspection
Talking to a DBUS object from PHP
Activating the screensaver

 screensaver.php:
  <?php
  $d = new Dbus;
  $n = $d->createProxy(
      "org.gnome.ScreenSaver",
      "/org/gnome/ScreenSaver",
      "org.gnome.ScreenSaver"
  );

  var_dump($n->GetActive());
  $n->SetActive( true );
  var_dump($n->GetActive());
  sleep(5);
  $n->SetActive( false );
  ?>
Kindle
Kindle Hacking




Playing around with your Kindle can make Amazon
angry
Kindle Hacking




In order to get shell, you have to do the following:
● Install a jailbreak

● Install USB networking

● Install Launchpad

● http://www.mobileread.com/forums/showthread.ph


  p?t=88004
Kindle Hacking
Getting PHP on the Kindle




 ●   Install the cross compilers from Emdebian:
     echo "deb http://www.emdebian.org/debian/ testing main"
     >> /etc/apt/sources.list
     apt-get update
     apt-get install gcc-4.3-arm-linux-gnueabi
 ●   Cross compile PHP
 ●   Copy it over and run:
     scp sapi/cli/php root@kindle:/tmp
     ssh root@kindle /tmp/php
     [root@kindle root]# /tmp/php -v PHP 5.3.6-dev (cli) (built:
     Mar 7 2011 13:42:56) Copyright (c) 1997-2011 The PHP Group
     Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend
     Technologies
Kindle Hacking
Cross-compiling

 ●   Install the cross compilers from Emdebian:
     echo "deb http://www.emdebian.org/debian/ testing main" >>
     /etc/apt/sources.list
     apt-get update
     apt-get install gcc-4.3-arm-linux-gnueabi
 ●   Configure "like normal":
     CC='arm-linux-gnueabi-gcc'  '/home/derick/dev/php/php-
     src/branches/PHP_5_3/configure'  '--disable-all'  '--
     prefix=/home/derick/install/kindle/cross/target'  '--enable-
     sockets'  '--enable-pcntl'  '--with-pcre-regex'
 ●   make
 ●   Edit the last line, remove everything until arm-
     linux-gnueabi-gcc
 ●   Add -static after -fvisibility=hidden
 ●   Replace every .lo with .o
 ●   Run
     arm-linux-gnueabi-gcc -export-dynamic -g -O2 -fvisibility=hidden
     -static ext/date/php_date.o .... -lcrypt -o sapi/cli/php
Kindle Hacking

The Kindle:
● Runs Linux

● Does not run X, but a framebuffer

● Has WiFi (and 3G), but requires a proxy to work


Getting GTK to run on framebuffer is a pain, and so
far I have not managed to get PHP-GTK running on
it.
Kindle Hacking
Accessing the screen

 ●   Open framebuffer /dev/fb0
 ●   mmap the open file
 ●   Screen data is stored with every two pixels stored
     in one byte, in total 800 rows, with 300 bytes per
     row (600 pixels)
  (40 more)
  66 55 55 65 66 54 45 68 CF FF (290 more)
  77 77 66 78 77 65 65 55 7B FF (290 more)
  (858 more)

  7B =   0111 1011
         `--´ `--´
         |     `---- 2nd nibble: 11/15
         `----------1st nibble:   7/15
Kindle Hacking
Downloading files from PHP

 You need to use Amazon's proxy
 ● Each request with the proxy needs to be


   authenticated, otherwise:
    HTTP/1.1 403 Forbidden+for+Client3A+amz5F2020
    Date: Thu, 03 Mar 2011 20:54:10 GMT
    Content-Type: text/html
    Transfer-Encoding: chunked
    x-kn-retry: 300

    There is a problem with your Kindle account. Please call Customer Service at 1-866-321-8851 or 1-206-266-0927. For UK
    customers, please call +44(0)800 496 2449.

  <?php
  $url = "tcp://87.238.83.84:80";
  $fp = stream_socket_client($url, $errno, $errstr, 1);
  if (!$fp) {
      echo "$errstr ($errno)<br />n";
  } else {
      fwrite($fp, <<<ENDREQ
  GET http://derickrethans.nl/ws/tubestatus.ws.php HTTP/1.1r
  Host: derickrethans.nlr
  User-Agent: Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0
  (screen 600x800; rotate)r
  Referer: http://mobile.twitter.com/r
  Cache-Control: max-age=0r
  Accept-Encoding: gzipr
  Accept-Language: en-USr
  x-fsn: R0pdR...personal-key...qpxX1Jr
  x-kn-appId: BBookletV3r
  r
  r
  ENDREQ
      );
      while (!feof($fp)) {
           echo fgets($fp, 1024);
      }
      fclose($fp);
  }?>
Kindle Hacking

What is left?
● A PHP extension to talk to the screen

● Figure out how to stop the Kindle's main


  application from running when our own app is
  going
● How to write an interface, and or interface with


  the keyboard just like the Kindle does
Conclusion

●   Mobile devices have little memory and CPU power
●   Bandwidth is a real issue
●   Lack of APIs
●   PHP can run on them, but whether it's smart is to
    be seen
●   Issues with proprietary systems
●   Next experiment: PHP on Android/WebOS/Meego?
Thanks!

Derick Rethans - derick@php.net - twitter: @derickr
             http://derickrethans.nl/talks.html
                     http://joind.in/2823

Weitere ähnliche Inhalte

Was ist angesagt?

TriplePlay-WebAppPenTestingTools
TriplePlay-WebAppPenTestingToolsTriplePlay-WebAppPenTestingTools
TriplePlay-WebAppPenTestingTools
Yury Chemerkin
 

Was ist angesagt? (19)

TriplePlay-WebAppPenTestingTools
TriplePlay-WebAppPenTestingToolsTriplePlay-WebAppPenTestingTools
TriplePlay-WebAppPenTestingTools
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
04 web optimization
04 web optimization04 web optimization
04 web optimization
 
X-Debug in Php Storm
X-Debug in Php StormX-Debug in Php Storm
X-Debug in Php Storm
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
SREConEurope15 - The evolution of the DHCP infrastructure at Facebook
SREConEurope15 - The evolution of the DHCP infrastructure at FacebookSREConEurope15 - The evolution of the DHCP infrastructure at Facebook
SREConEurope15 - The evolution of the DHCP infrastructure at Facebook
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
Apache httpd reverse proxy and Tomcat
Apache httpd reverse proxy and TomcatApache httpd reverse proxy and Tomcat
Apache httpd reverse proxy and Tomcat
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Fluentd and WebHDFS
Fluentd and WebHDFSFluentd and WebHDFS
Fluentd and WebHDFS
 
Fluentd - road to v1 -
Fluentd - road to v1 -Fluentd - road to v1 -
Fluentd - road to v1 -
 
Debugging PHP With Xdebug
Debugging PHP With XdebugDebugging PHP With Xdebug
Debugging PHP With Xdebug
 
Lukas Macura - Employing Zabbix to monitor OpenWrt (Beesip) devices with Uciprov
Lukas Macura - Employing Zabbix to monitor OpenWrt (Beesip) devices with UciprovLukas Macura - Employing Zabbix to monitor OpenWrt (Beesip) devices with Uciprov
Lukas Macura - Employing Zabbix to monitor OpenWrt (Beesip) devices with Uciprov
 
From a cluster to the Cloud
From a cluster to the CloudFrom a cluster to the Cloud
From a cluster to the Cloud
 
Python at Facebook
Python at FacebookPython at Facebook
Python at Facebook
 
Joomla on Raspberry Pi using Nginx - Nederlandse Linux Gebruikers Group novem...
Joomla on Raspberry Pi using Nginx - Nederlandse Linux Gebruikers Group novem...Joomla on Raspberry Pi using Nginx - Nederlandse Linux Gebruikers Group novem...
Joomla on Raspberry Pi using Nginx - Nederlandse Linux Gebruikers Group novem...
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx Internals
 
Your Inner Sysadmin - MidwestPHP 2015
Your Inner Sysadmin - MidwestPHP 2015Your Inner Sysadmin - MidwestPHP 2015
Your Inner Sysadmin - MidwestPHP 2015
 

Ähnlich wie Php Inside - confoo 2011 - Derick Rethans

Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
Combell NV
 
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
phpbarcelona
 
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison DowdneySetting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Weaveworks
 

Ähnlich wie Php Inside - confoo 2011 - Derick Rethans (20)

(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems
 
Beyond Puppet
Beyond PuppetBeyond Puppet
Beyond Puppet
 
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-)
 
Why we choose Symfony2
Why we choose Symfony2Why we choose Symfony2
Why we choose Symfony2
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud RunDesigning flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
Designing flexible apps deployable to App Engine, Cloud Functions, or Cloud Run
 
Internationalizing The New York Times
Internationalizing The New York TimesInternationalizing The New York Times
Internationalizing The New York Times
 
New Jersey Red Hat Users Group Presentation: Provisioning anywhere
New Jersey Red Hat Users Group Presentation: Provisioning anywhereNew Jersey Red Hat Users Group Presentation: Provisioning anywhere
New Jersey Red Hat Users Group Presentation: Provisioning anywhere
 
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10Php through the eyes of a hoster: PHPNW10
Php through the eyes of a hoster: PHPNW10
 
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison DowdneySetting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
Setting up Notifications, Alerts & Webhooks with Flux v2 by Alison Dowdney
 
Improving Operations Efficiency with Puppet
Improving Operations Efficiency with PuppetImproving Operations Efficiency with Puppet
Improving Operations Efficiency with Puppet
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
 
Monkey Server
Monkey ServerMonkey Server
Monkey Server
 
Owasp AppSecEU 2015 - BeEF Session
Owasp AppSecEU 2015 - BeEF SessionOwasp AppSecEU 2015 - BeEF Session
Owasp AppSecEU 2015 - BeEF Session
 

Mehr von Bachkoutou Toutou

Making php see, confoo 2011
Making php see, confoo 2011 Making php see, confoo 2011
Making php see, confoo 2011
Bachkoutou Toutou
 
Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011
Bachkoutou Toutou
 
hacking your website with vega, confoo2011
hacking your website with vega, confoo2011hacking your website with vega, confoo2011
hacking your website with vega, confoo2011
Bachkoutou Toutou
 
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Bachkoutou Toutou
 
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Bachkoutou Toutou
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011
Bachkoutou Toutou
 
Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011
Bachkoutou Toutou
 
Connecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafooConnecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafoo
Bachkoutou Toutou
 
99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievski99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievski
Bachkoutou Toutou
 
WebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coatesWebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coates
Bachkoutou Toutou
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
Bachkoutou Toutou
 
Confoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsConfoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO Patterns
Bachkoutou Toutou
 

Mehr von Bachkoutou Toutou (14)

Making php see, confoo 2011
Making php see, confoo 2011 Making php see, confoo 2011
Making php see, confoo 2011
 
Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011
 
hacking your website with vega, confoo2011
hacking your website with vega, confoo2011hacking your website with vega, confoo2011
hacking your website with vega, confoo2011
 
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
Premiers pas dans les extensions PHP, Pierrick Charron, Confoo 2011
 
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
Kill bottlenecks with gearman, sphinx, and memcached, Confoo 2011
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011
 
Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011Connecting web Applications with Desktop, confoo 2011
Connecting web Applications with Desktop, confoo 2011
 
Connecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafooConnecting Web Application and Desktop, confoo 2011, qafoo
Connecting Web Application and Desktop, confoo 2011, qafoo
 
99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievski99 problems but the search aint one, confoo 2011, andrei zmievski
99 problems but the search aint one, confoo 2011, andrei zmievski
 
WebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coatesWebShell - confoo 2011 - sean coates
WebShell - confoo 2011 - sean coates
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
Apc Memcached Confoo 2011
Apc Memcached Confoo 2011Apc Memcached Confoo 2011
Apc Memcached Confoo 2011
 
Xdebug confoo11
Xdebug confoo11Xdebug confoo11
Xdebug confoo11
 
Confoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsConfoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO Patterns
 

Php Inside - confoo 2011 - Derick Rethans

  • 1. Welcome! PHP Inside ConFoo - Montréal, Canada - March 10th, 2011 Derick Rethans - derick@php.net - twitter: @derickr http://derickrethans.nl/talks.html http://joind.in/2823
  • 2. About Me Derick Rethans ● Dutchman living in London ● PHP development ● Author of the mcrypt, input_filter, dbus, translit and date/time extensions ● Author of Xdebug ● Contributor to the Apache Zeta Components Incubator project (formerly eZ Components) ● Freelancer doing PHP (internals) development
  • 5. My First Application ● is the new hello world ● Simple web API to get data ● Authentication with HTTP basic auth ● Simple interface: some buttons, an edit box and a list of tweets
  • 6. GUI toolset ● is a PHP binding for the GTK+ widget set ● It comes as an extension for PHP ● It wraps around many GTK+ widgets ● GUI can be created from PHP: <?php $tb = new GtkToolbar(); $tb->set_show_arrow( false ); $tb->set_property( 'toolbar-style', Gtk::TOOLBAR_BOTH ); $tb->set_property( 'icon-size', 6 ); $this->updatebutton = GtkToolButton::new_from_stock( Gtk::STOCK_REFRESH ); $lbl = new GtkLabel(); $lbl->set_markup( '<span underline="single">U</span>pdate' ); $this->updatebutton->set_label_widget( $lbl ); $this->updatebutton->connect_simple( 'clicked', array( $this, 'update' ) ); $this->updatebutton->add_accelerator( 'clicked', $accels, Gdk::KEY_U, Gdk::MOD1_MASK, 0 ); $this->updatebutton->set_use_underline( true ); $tb->insert( $this->updatebutton, -1 );
  • 7. Getting PHP on the device ● It's an ARM processor ● Cross compiling vs compiling on the device Cross-compiling: ● Requires cross-compilation set-up ● Tricky, and caused libtool problems for me Compiling on the device ● All packages need to be found and installed ● Compiling PHP is really slow, you really don't want to use make clean
  • 8. Data Storage ● You can't really run a database server on the phone ● SQLite is part of PHP, and self-contained ● Indexes are vital on this platform ● Clever use of SQL/Data manipulation is required for performance
  • 9. Twitter App Experiences ● Starting the app is not fast ● Styling with GTK is tricky, especially if you want to run the app on the desktop too ● Twitter API is very unstable, and inaccessible at times; it's also badly designed ● You pull in way too much data than you need ● My fingers are really fat ● Can't really have the app running for a long time
  • 12. Transport for London ● Provides status updates through ● If you're traveling, it's really handy to have this information with you ● There is no API, so you need to scrape ● Widget provided for embedding: ● Strict rules about colours etc.: ● It's probably not totally legal
  • 13. Scraping the Tube status ● It's a ~25kb download; with GPRS the download time is about 5 seconds ● It has lots of mark-up and JavaScript that we're not interested in ● Using PHP to get the data we want from it is relatively slow ● If the format changes, all the installed apps need to be updated
  • 14. Web API ● The download with status is only 0.5kb ● The API caches the download ● It only provides the data in JSON that we require: { "date":1273835118, "status":[ ["Bakerloo",["Good service",""]],["Central",["Good service",""]], ["Circle",["Good service",""]],["District",["Good service",""]], ["H'smith & City",["Good service",""]],["Jubilee",["Good service",""]], ["Metropolitan",["Good service",""]],["Northern",["Good service",""]], ["Piccadilly",["Good service",""]],["Victoria",["Good service",""]], ["Waterloo & City",["Good service",""]] ] } ● Parsing the JSON is fast, very little processing needed in the app, just display ● If the HTML changes, only the scraping algorithm needs to be changed
  • 16. Talking to the hardware ● Many applications (phonebook, sending SMS) that came with the phone where suboptimal ● Writing a new GUI is possible, but talking to the hardware requires D-BUS ● D-BUS APIs are exposed by the freesmartphone project that the Linux distribution uses ● PHP didn't have a D-BUS extension
  • 17. PHP DBUS extension ● DBUS bindings using the low-level C library (libdbus) ● Provides proxy objects ● Implements automatic-marshalling of data ● Provides specific classes for full control ● Support for method invocation, method calls, sending and receiving signals ● (Basic) support for introspection
  • 18. Talking to a DBUS object from PHP Activating the screensaver screensaver.php: <?php $d = new Dbus; $n = $d->createProxy( "org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver" ); var_dump($n->GetActive()); $n->SetActive( true ); var_dump($n->GetActive()); sleep(5); $n->SetActive( false ); ?>
  • 20. Kindle Hacking Playing around with your Kindle can make Amazon angry
  • 21. Kindle Hacking In order to get shell, you have to do the following: ● Install a jailbreak ● Install USB networking ● Install Launchpad ● http://www.mobileread.com/forums/showthread.ph p?t=88004
  • 22. Kindle Hacking Getting PHP on the Kindle ● Install the cross compilers from Emdebian: echo "deb http://www.emdebian.org/debian/ testing main" >> /etc/apt/sources.list apt-get update apt-get install gcc-4.3-arm-linux-gnueabi ● Cross compile PHP ● Copy it over and run: scp sapi/cli/php root@kindle:/tmp ssh root@kindle /tmp/php [root@kindle root]# /tmp/php -v PHP 5.3.6-dev (cli) (built: Mar 7 2011 13:42:56) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
  • 23. Kindle Hacking Cross-compiling ● Install the cross compilers from Emdebian: echo "deb http://www.emdebian.org/debian/ testing main" >> /etc/apt/sources.list apt-get update apt-get install gcc-4.3-arm-linux-gnueabi ● Configure "like normal": CC='arm-linux-gnueabi-gcc' '/home/derick/dev/php/php- src/branches/PHP_5_3/configure' '--disable-all' '-- prefix=/home/derick/install/kindle/cross/target' '--enable- sockets' '--enable-pcntl' '--with-pcre-regex' ● make ● Edit the last line, remove everything until arm- linux-gnueabi-gcc ● Add -static after -fvisibility=hidden ● Replace every .lo with .o ● Run arm-linux-gnueabi-gcc -export-dynamic -g -O2 -fvisibility=hidden -static ext/date/php_date.o .... -lcrypt -o sapi/cli/php
  • 24. Kindle Hacking The Kindle: ● Runs Linux ● Does not run X, but a framebuffer ● Has WiFi (and 3G), but requires a proxy to work Getting GTK to run on framebuffer is a pain, and so far I have not managed to get PHP-GTK running on it.
  • 25. Kindle Hacking Accessing the screen ● Open framebuffer /dev/fb0 ● mmap the open file ● Screen data is stored with every two pixels stored in one byte, in total 800 rows, with 300 bytes per row (600 pixels) (40 more) 66 55 55 65 66 54 45 68 CF FF (290 more) 77 77 66 78 77 65 65 55 7B FF (290 more) (858 more) 7B = 0111 1011 `--´ `--´ | `---- 2nd nibble: 11/15 `----------1st nibble: 7/15
  • 26. Kindle Hacking Downloading files from PHP You need to use Amazon's proxy ● Each request with the proxy needs to be authenticated, otherwise: HTTP/1.1 403 Forbidden+for+Client3A+amz5F2020 Date: Thu, 03 Mar 2011 20:54:10 GMT Content-Type: text/html Transfer-Encoding: chunked x-kn-retry: 300 There is a problem with your Kindle account. Please call Customer Service at 1-866-321-8851 or 1-206-266-0927. For UK customers, please call +44(0)800 496 2449. <?php $url = "tcp://87.238.83.84:80"; $fp = stream_socket_client($url, $errno, $errstr, 1); if (!$fp) { echo "$errstr ($errno)<br />n"; } else { fwrite($fp, <<<ENDREQ GET http://derickrethans.nl/ws/tubestatus.ws.php HTTP/1.1r Host: derickrethans.nlr User-Agent: Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600x800; rotate)r Referer: http://mobile.twitter.com/r Cache-Control: max-age=0r Accept-Encoding: gzipr Accept-Language: en-USr x-fsn: R0pdR...personal-key...qpxX1Jr x-kn-appId: BBookletV3r r r ENDREQ ); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); }?>
  • 27. Kindle Hacking What is left? ● A PHP extension to talk to the screen ● Figure out how to stop the Kindle's main application from running when our own app is going ● How to write an interface, and or interface with the keyboard just like the Kindle does
  • 28. Conclusion ● Mobile devices have little memory and CPU power ● Bandwidth is a real issue ● Lack of APIs ● PHP can run on them, but whether it's smart is to be seen ● Issues with proprietary systems ● Next experiment: PHP on Android/WebOS/Meego?
  • 29. Thanks! Derick Rethans - derick@php.net - twitter: @derickr http://derickrethans.nl/talks.html http://joind.in/2823