Added more control of php-webkit through package.json

This commit is contained in:
Brad Metcalf 2015-03-30 19:03:47 -05:00
commit 8164b247cf
4 changed files with 38 additions and 21 deletions

View file

@ -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

16
node_modules/node-php/main.js generated vendored
View file

@ -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
});

View file

@ -5,8 +5,10 @@
"main": "./php-webkit/index.html",
"node-remote": "<local>",
"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,

View file

@ -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,