PHP Export Compiler for AJAX Code
Brought to you by:
funkyrider
| File | Date | Author | Commit |
|---|---|---|---|
| README.txt | 2008-10-19 | FunkyRider | [r1] Initial working version, with two sample web ap... |
| myirc.html | 2008-10-19 | FunkyRider | [r1] Initial working version, with two sample web ap... |
| myirc.php | 2008-10-19 | FunkyRider | [r1] Initial working version, with two sample web ap... |
| myirc.sql | 2008-10-19 | FunkyRider | [r1] Initial working version, with two sample web ap... |
| pxc.java | 2008-10-19 | FunkyRider | [r2] Added async (callback) mode functions (/*PHP_CA... |
| simple.html | 2008-10-19 | FunkyRider | [r2] Added async (callback) mode functions (/*PHP_CA... |
| simple.php | 2008-10-19 | FunkyRider | [r2] Added async (callback) mode functions (/*PHP_CA... |
Project name: PHP Export Compiler for AJAX (pxc)
Author: Bo Z
License: GNU GPL v3
Introduction:
A meta-function compiler for PHP/JavaScript, to create clean
implementations of AJAX web applications. The code for set up
and invoke a XMLHTTP request, as well as the code for marshaling
data pass are generated from the source php script automatically.
Only need to invoke when PHP export function declaration changes.
Low overhead XMLHTTP requests in transparent implementation.
In PHP server side script create a function:
function /*PHP_EXPORT*/ say_hello($name)
{
return "Hello, {$name}!";
}
Compile using pxc will generate the inc and js files.
Include inc file in server side, include js file in client side.
In client side DHTML script invoke the call by:
function do_say_hello()
{
var result = say_hello("Name");
}
All data marshaling and communication are done transparently.
Design details:
In first scan stage, the pxc reads through a php script file, look
for any function with "/*PHP_EXPORT*/" comment inserted between
"function" keyword and its name, and register this function for export.
In the export stage, each of the functions marked as for export, will
be encapsulated in a .inc file and a .js file. The inc file is being
included in the source php file, the js file is included in client
side script which is going to call server side functions.
Inside the js file, each function is being declared as a proxy. When
called, it encodes the parameters and function name as POST data,
then invoke the XMLHTTP request. After the server processed the
XMLHTTP and returned the result, it passes the result to client
side caller in form of return value.
Inside the inc file there is a switch-case block, with the extracted
function name as case statements. It looks for matching function
name, extract all its parameters from the POST data and invoke it.
Up on finishing executing the server side function, it echos its
return value to client too. This way the server side function can
either send its result via echo function, or via the return value.
Project source list:
pxc.java
Project example list:
simple.php
simple.html
myirc.php
myirc.html
myirc.sql
Compile:
> javac pxc.java
Run example "simple":
required packages: apache2, php5 for apache
> java pxc simple
copy simple.php, simple.inc, simple.html, simple.js to /var/www
invoke in the web brower: http://localhost/simple.html
Run example "myirc":
required packages: apache2, php5 for apache, php5 for mysql, mysql server
> java pxc myirc
copy myirc.php, myirc.inc, myirc.html, myirc.js to /var/www
mysql use name "root", password "1234"
mysql import script myirc.sql
invoke in the web browser: http://localhost/myirc.html