Giix

januari 11, 2015 at 1:19 pm

Using (cake)PHP to create desktop applications

Using (cake)PHP to create desktop applications

I recently was looking for a way to ‘ship’ my PHP application to a customer for demonstrator / prototype review purposes. I first started looking for php to exe kind of packagers. There are some commercial tools that can do that but the one I really liked at first sight was phpdesktop! I also found Nightrain (http://www.nightrain.naetech.com/) which does almost the exact same but has a huge downside (in my opinion) and that is the Qt dependency. This requires my user to download and install 500+ Mb of Qt for Windows in order to run the application. The upside of Nightrain is the cross-platform support.

Back to the problem I needed solving; Shipping my entire application in a zip file containing a simple exe to start running my app. Phpdesktop obviously was the way to go and I started out by downloading it and placing my PHP code in the www directory. The framework I use for my applications is CakePHP (http://cakephp.org) and this required some extra steps to get it working. Before I get into detail about the exact steps taken I want to skip ahead to my final solution. In my early CakePHP years I once heard someone say; Pluginize all things, and that is exactly what I did. I embedded phpdesktop into a CakePHP plugin making it possible to install that plugin (called Cakedesktop) and create an offline phpdesktop-based CakePHP application directly from your web browser.

In short, any CakePHP user can download their web application to a desktop application. The steps the plugin currently takes are the following:

0. Retrieve options from initial webpage (users can specify things like full screen, application name, etc.)

1. Copy phpdesktop skeleton dir to tmp dir
2. Copy entire CakePHP directory to tmp dir’s www dir
3. Apply options for phpdesktop (as given in step 0)
4. Copy loaded php extensions to new php.ini (check loaded extensions and copy them tot be loaded in phpdesktops php.ini, to get max compatibility)
5. Remove .htaccess files (Mongoose has no mod_rewrite for pretty urls)
6. Edit core.php and bootstrap.php to disable url rewrite and remove this plugin
7. Dump MySQL database (pure php code, no mysqldump command)
8. Convert SQL to Sqlite compatible SQL (work in progress)
9. Edit database.php to activate Sqlite
10. Import database structure and data in Sqlite
11. Zip package
12. Cleanup job dir
13. Serve package

So that’s it folks, a complete PHP application as a standalone Windows desktop application in less than a minute depending on the speed of your webserver 😉

The project has been submitted and accepted to the CakePHP plugin repo (http://plugins.cakephp.org).

GitHub url: https://github.com/stefanvangastel/CakePHP-Cakedesktop

And of course my thanks to Czarek Tomczak! Keep up the good work!

(Originally posted in https://groups.google.com/forum/#!topic/phpdesktop/zg5OfGwVWqs) 

0 likes cakephp , php # , ,
Share: / / /

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *