PHP 5.4 http client-side Proof of Concept
Originally posted [1]
"Among other things php 5.4 introduces is the http server, which is marked as development only, but seems very stable, I've been looking at it for months now.
This is why... very rough and ready Proof of Concept
Contents |
Proof of Concept
Here a browser window is calling to php5.4 http server and asking for wxphp to present a file open dialogue, and then write back by ajax an image tag SRC, that will request the selected filename, which will be returned raw to the browser by php ...
Originally from Wiki Commons by Mr.choppers (click image for more information) ... found by wxphp wxWdiget file dialogue, and then sent raw by php5, to the browser to avoid cross domain issues.
What I am doing is working with php 5.4's http server, to make use of any html5 browser (Chrome or the portable opensource QtWeb qtweb.net - less encumbered than Chrome) at moment.
Router Script .php
I use the php 5.4 http server, with a router.php script, to receive requests (all on the client machine). Then exec() out to wxphp for things that the browser can not handle, like local file dialogue boxes, and more complex things that wxphp project has enabled.
Batch File Starts PHP Built-in server
This simple batch file starts the server (php 5.4 - set your own port number here 8888),
Code:
php -S localhost:8888 phpserver.php
And so I point the browser at http://localhost:8888/docs/index.html
phpserver.php is my very rough and ready proof of concept router script. When a local image is required, I need to ask for and send it to the browser in raw, due to browser cross domain issues, but that is a minor thing.
Code PHP5.4 http Router Script=
<?php
if (strpos(strtolower($_SERVER['QUERY_STRING']), ".jpg") > -1 | strpos(strtolower($_SERVER['QUERY_STRING']), ".png") > -1)
{
$getThisFile = urldecode( $_SERVER['QUERY_STRING']);
$fn=fopen($getThisFile,'r');
fpassthru($fn);
}
else
{
switch( $_SERVER['QUERY_STRING'])
{
case 'getfilename':
echo exec('php-5.3.9-nts\php "..\fileDialogue\fileDialogueDirect.php"');
//G:\hold\wxForms
break;
default:
return false;
}
}
?>
My index.html (still marked transitional just for now) stored under my php 5.4.0 directory in /docs folder (or any other names /tree you may wish to make)
Code index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
<!--
function getFileName()
{
jQuery.get('http://localhost:8888?getfilename', function(data) {
// alert(data);
hold = data;
if (hold.toLowerCase().indexOf('.jpg') > -1 | hold.toLowerCase().indexOf('.png') > -1)
{
hold='<img width="640" src="?' + hold.replace(/\\/g,"/") + '" alt="My Picture">';
}
$('#fileNameDisplay').html(hold);
// alert('Load was performed.');
});
}
//-->
</script>
</head>
<body>
<button onclick="getFileName()">Get File Name</button><p />
<div id="fileNameDisplay"></div>
</body>
</html>
The button click through the php 5.4 http server calls this wxphp script...
Code Wxphp Script
<?php
class myApp extends wxApp
{
function OnInit()
{
$openFileDialog = new wxFileDialog(null, "Open Any file", "", "",
"All files (*.*)|*.*", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if ($openFileDialog->ShowModal() == wxID_CANCEL)
{
exit(0);}
// to shell
exit($openFileDialog->GetPath());
return 0;
}
function OnExit()
{
return 0;
}
}
//-?- // define('wxUSE_GUI', 0);
$xt = new myApp();
wxApp::SetInstance($xt);
wxEntry();
?>
Other Helpers
Added to that kind of scenario, where there are any holes, using GlueScript (http://gluescript.sourceforge.net/) which is JavaScript with some of the wxWidget set, client-side, using poco libraries to add extra features beyond wxWdigets.
html5, css3, web libraries, wxWidgets, and php5
With wxphp, all this means that all the extensive libraries available through jQuery and like can be used in the browser client side as primary interface, and wxphp for all local client disk and more complex local interface needs through calls from the php http server.
Exposes all of html5, css3, many many various web libraries, wxWidgets, and the power of php5. All cross platform ...
Very effective local application scenario tests so far, and extremely versatile.
At the moment I am having to use both php 5.3.9 (for wxphp) and php 5.4 RC (for php http server), but it works well and no Apache installation needed at all as far as I can see.

