Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few...
Transcript of Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few...
![Page 1: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/1.jpg)
Building Desktop RIAs with PHP and JavaScriptEd Finkler • funkatron.com • @funkatronCodeWorks 09
![Page 2: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/2.jpg)
What to expect
This is mainly a JavaScript talk
Compare JS and PHP
jQuery framework for JS examples
This is mainly a desktop app dev talk
Diffs between server app dev and desktop app dev
Examples of desktop app <-> server app interaction
![Page 3: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/3.jpg)
Web runtimes
A browser engine environment used for building "local" apps
![Page 4: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/4.jpg)
Current web runtimesAIR (adobe.com/go/air)
Desktop
Titanium (titaniumapp.com)
Desktop
Mobile
Palm webOS (developer.palm.com)
Mobile
![Page 5: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/5.jpg)
We'll use AIR
But others bear examination
![Page 6: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/6.jpg)
JavaScript in AIRCan use (almost) any available JS libs/frameworks
No cross-domain restrictions
security restrictions in app sandbox ( eval() )
Access AIR APIs
Access standard Flash APIs
Use compiled AS3 libs
![Page 7: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/7.jpg)
PHP vs JavaScript
JavaScript is fundamentally different
JS is a functional language
closures
first-order functions
Object model is totally different
![Page 8: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/8.jpg)
PHP vs JavaScript
Everything in JS is an object
Arrays are not associative – objects serve as associative array equivalents
No include/require statements available
Event-driven model/asynchronous actions
Further reading: – JavaScript: The Definitive Guide, David Flanagan – MDC JavaScript Guide; MDC JavaScript Ref
![Page 9: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/9.jpg)
Desktop vs Server-side
PHP stack is built up/torn down every time
mem leaks not much of an issue
exec time < a few seconds max
almost always synchronous calls
Desktop apps are persistent
exec time can be hours or days
mem leaks a HUGE issue
lots of asynchronous calls
![Page 10: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/10.jpg)
JavaScript frameworks
Some stuff is a huge pain without the help of a framework
Lots of choices
Must play well with AIR
eval usage gotchas
![Page 11: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/11.jpg)
jQuery pwnz yoo
jQuery is teh awesomebut you can use anything
![Page 12: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/12.jpg)
PHPtubby jedi master
JavaScripthyper frontman
PHP is your server-side buddy
Use 5.2 at least (you are, right?)
adds native JSON encoding/decoding
![Page 13: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/13.jpg)
PHP talking to AIR
Serve data structures instead of HTML
Use JSON
Use JSON
USE JSONdo not use XML (if you can avoid it)
set the correct mime type (application/json)
![Page 14: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/14.jpg)
Example 1:PHP duz yer math
Async calls using jQuery AJAX methods
Communicate via JSON
Zee Cloudweb server
Webkit
Flash
![Page 15: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/15.jpg)
Example 2:PHP 'shops yer pics
Uploading via Flash APIs
JSON based communication
Zee Cloudweb server
Webkit
Flash
![Page 16: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/16.jpg)
Example 3:DearZend.com
JSON based communication
Desktop alternative to web front-end
Zee Cloudweb server
Webkit
Flash
![Page 17: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/17.jpg)
Additional resourcesAdobe AIR for JavaScript Developers Pocketguidehttp://www.tostring.org/
Developing Adobe® AIR™ Applications with HTML and Ajaxhttp://short.ie/ggd9tc
Titaniumhttp://titaniumapp.com/
Titanium Forumshttp://short.ie/d4ponk
Searchatron Sourcehttp://short.ie/g9z6qt
DearZend.com sourcehttp://github.com/funkatron/dearzend-serverhttp://github.com/funkatron/dearzend-client
![Page 18: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/18.jpg)
Additional resourcesSpaz Desktop Sourcehttp://code.google.com/p/spaz/
Spaz webOS Sourcehttp://github.com/funkatron/spaz-webos/
SpazCorehttp://github.com/funkatron/spazcore
![Page 19: Building Desktop RIAs with PHP and JavaScript · mem leaks not much of an issue exec time < a few seconds max almost always synchronous calls Desktop apps are persistent exec time](https://reader034.fdocuments.net/reader034/viewer/2022043001/5f7c44dca2bf6d7fa52c04c2/html5/thumbnails/19.jpg)
Questions?@funkatron • http://funkatron.com • joind.in