My PHP program calls a serverside JavaScript via CasperJS. It looks this way:
<?php
echo shell_exec('casperjs doSomething.js '.escapeshellarg(json_encode($_GET)));
?>
All params in $_GET are encoded into one string and it is transferred as the first shell argument. This works because it is escaped first. The shell_exec calls the server-side JavaScript. The result of the JavaScript is returned using echo.
In JavaScript the params in the first commandline argument are decoded again:
var paramlist='';
paramList=JSON.parse(casper.cli.get(0));
var param1=paramList.aParam;
.cli is the command line interface. The params can be accessed using their names. That's rather easy, direct and short.
A result in JavaScript can be transferred via JSON too:
this.echo('{"res1":"'+param1+'","res2":"'+paramList.bParam+'"}');
Regards, Harald