From 8164b247cfca2c919543521d4de3f83f9085119e Mon Sep 17 00:00:00 2001 From: Brad Metcalf Date: Mon, 30 Mar 2015 19:03:47 -0500 Subject: [PATCH] Added more control of php-webkit through package.json --- README.md | 10 ++++++++-- node_modules/node-php/main.js | 16 ++-------------- package.json | 6 ++++-- php-webkit/main.js | 27 ++++++++++++++++++++++++--- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 9c5757b..14bd2f5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Introduction -The goal of php-webkit is to be able to package a PHP app within a [NW.js](http://nwjs.io/) project without needing the user to install and set up PHP on their system or connect to a remote PHP codebase. This repository is what your NW.js project should be set up as to succeed this objective. When your NW.js application is executed node.js starts up an internal PHP web server using the binaries in the php directory. This web server will start up any PHP project you have in the application directory. You can modify php-webkit itself in the associated directory as well as the package.json to fit your application's needs. Just be sure not to change anything that will break php-webkit's ability to run properly. The end result is a PHP desktop application that is also capable of executing node.js code. +The goal of php-webkit is to be able to package a PHP app within a [NW.js](http://nwjs.io/) project without needing the user to install and set up PHP on their system or connect to a remote PHP codebase. This repository is what your NW.js project should be set up as to succeed this objective. When your NW.js application is executed node.js starts up an internal PHP web server using the binaries in the php directory. This web server will start up any PHP project you have in the application directory. You can modify php-webkit's files as well as the ```package.json``` to fit your application's needs. Just be cautious not to change anything that will break php-webkit's ability to run properly. The end result is a PHP desktop application that is also capable of executing node.js code. ## Packaging and Distributing @@ -10,7 +10,13 @@ You can create a PHP desktop app by going to [NW.js](http://nwjs.io/), downloadi ## Multiple Platforms -Although it may need a little additonal work you can make a PHP desktop application for Windows, Linux, and OSX. Currently the binaries for PHP are version 5.6 32-bit thread safe binaries for Windows. But you can switch it out with a different version/platform found at [PHP.net](http://php.net/) or elsewhere. Linux and OSX versions have a slightly different file structure and so far a packaging scheme has not been decided. As a result a call is made for php-cgi opposed to a determined project directory. This requires a seperate install of PHP for Linux and OSX until this is resolved. Have suggestions? Do feel free to share. +Although it may need a little additonal work you can make a PHP desktop application for Windows, Linux, and OSX. Currently the binaries for PHP are version 5.6 32-bit thread safe binaries for Windows. But you can switch it out with a different version/platform found at [PHP.net](http://php.net/) or elsewhere. Linux and OSX versions have a slightly different file structure and so far a packaging scheme has not been decided so you will need to come up with your own. Have suggestions? Do feel free to share. + +(I have not tested it on any ARM based builds of NW.js but I don't see why it couldn't work.) + +## Packaging PHP Optional + +You may wish to use PHP within a NW.js project but don't want to package it within your application binary. You can either move it outside the directory or use the machines installed version of PHP if applicable. If you want to move it to another folder specify the new location as ```bin``` in your ```package.json```. It can even be outside of your project directory. If PHP is installed properly you can simply put ```php-cgi``` in this field instead. Don't forget to delete the existing php directory to save on hard disk space and make unpacking faster. ## Server Variables diff --git a/node_modules/node-php/main.js b/node_modules/node-php/main.js index 2b5dd6c..a0d695a 100644 --- a/node_modules/node-php/main.js +++ b/node_modules/node-php/main.js @@ -24,7 +24,7 @@ function runPHP(req, response, next, phpinfo){ var env = { SERVER_SIGNATURE: "php-webkit", - PW_BIN_PATH: path.dirname(process.execPath), + PW_BIN_$$PATH: path.dirname(process.execPath), PW_BIN_FILE: process.execPath, PW_ARGUMENTS: phpinfo.arguments, PW_MANIFEST: phpinfo.manifest, @@ -70,19 +70,7 @@ function runPHP(req, response, next, phpinfo){ if(/.*?\.php$/.test(file)){ var res = "", err = ""; - var os = require('os'); - var os = os.platform(); - - if(os == 'win32' || os == 'win64') { - var phpbin = './php/php-cgi.exe'; - } else if(os == 'darwin') { - var phpbin = 'php-cgi'; //Take a chance on finding an installed copy - } else if(os == 'linux') { - var phpbin = 'php-cgi'; //Take a chance on finding an installed copy - } else { - var phpbin = 'php-cgi'; //Take a chance on finding an installed copy - } - var php = child.spawn(phpbin, [], { + var php = child.spawn(phpinfo.bin, [], { env: env }); diff --git a/package.json b/package.json index d91a047..ac89c40 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ "main": "./php-webkit/index.html", "node-remote": "", "phpwebkit": { - "host": "127.0.0.1", - "port": 9090 + "bin": "", //The location of your php-cgi binary + "path": "./application", //The path to your PHP application + "host": "127.0.0.1", //The host the PHP app runs on + "port": 9090 //The port the PHP app runs on }, "window": { "toolbar": false, diff --git a/php-webkit/main.js b/php-webkit/main.js index 0158d38..3babdf0 100644 --- a/php-webkit/main.js +++ b/php-webkit/main.js @@ -4,21 +4,42 @@ var http = require('http'); var php = require('node-php'); var express = require('express'); var app = express(); +var os = require('os'); +var os = os.platform(); win.title = gui.App.manifest.name; +var bin = gui.App.manifest.phpwebkit.bin; +if(bin === undefined || bin == "") { + if(os == 'win32' || os == 'win64') { + bin = './php/php-cgi.exe'; + } else if(os == 'darwin') { + bin = './php/php-cgi'; + } else if(os == 'linux') { + bin = './php/php-cgi'; + } else { + bin = 'php-cgi'; + } +} + +var path = gui.App.manifest.phpwebkit.path; +if(path === undefined || path == "") { + path = './application'; +} + var host = gui.App.manifest.phpwebkit.host; -if(host === undefined) { +if(host === undefined || host == "") { host = '127.0.0.1'; } var port = gui.App.manifest.phpwebkit.port; -if(port === undefined) { +if(port === undefined || port == "") { port = 9090; } var phpinfo = { - "path": "./application", + "path": path, + "bin": bin, "host": host, "port": port, "arguments": gui.App.argv,