I have an Ajax-oriented website, the content of which is populated with requests from the βoperatorβ of a PHP script.
Although these queries usually occur in Javascript, there are times when it is useful to request my statement from another PHP script.
The method I used was to pass the url with the query string through file_get_contents()- and then parse the returned JSON with json_decode().
For several reasons, I would like to avoid this implementation, though ... I see in my error logs that URL requests are much more prone to crash for any reason - and I read that it is not very efficient.
My first attempt at making a universal query_operator($query_string)-type function is simply require()-ed operator.phpin the output buffer captured with ob_get_contents(). I also temporarily reset the $ _REQUEST array with parameters parsed from $query_string.
There were too many flaws in this approach - problems with the variable scope and the MySQL connection in particular.
My second attempt involved using the backtick operator (equivalently shell_exec()) and matching arguments $argvto an array $_REQUEST.
This approach works very well, but on the host I'm using, the PHP version (cli) is set to 4.4.8 - and I need 5.2.x. Assuming I can't switch the version (cli), what is the best best way to isolate a request to another PHP script using a query string? Any suggestions were greatly appreciated.
:
function query_operator($query) {
$query = '--'.str_ireplace('&', ' --', $query);
$contents = `php operator.php $query`;
if ($json = json_decode($contents, true)) {
return $json;
} else {
return $contents;
}
}