Running PHP in a web server “environment” without Apache (or another web server)

Is it possible to execute PHP code from a program that does not interact with a script through a web server? I initially thought of a PHP CLI interpreter, but it does not contain any $ _SERVER or $ _REQUEST cooking elements common to website requests.

So, if you can imitate, how could you accumulate? I do not think about any specific programming language, since I am sure that there is some common interface between web servers and php that would be platform independent.

The purpose of this question is to create a Node.JS application that can work as a web server, and then (if necessary) can execute PHP scripts (with specific inputs), extract the answer, and then, if necessary, perform some additional processing on the output, then write to his client.

+5
source share
1 answer

If you do not want to create a PHP module for Node.JS, I think that the CLI is your only choice - you can pass the necessary variables through the command line, and I think that says nothing about rebuilding them inside the script

php -f myscript.php /websites/myscript domain.com 1.2.3.4.5

Now, the ideal way would be to take these arguments and write them into variables that you then use in your script.

script, $_SERVER , , . (Inelegant, $_SERVER, $_GET ..)

$_SERVER["REQUEST_URI"] = $argv[1];
$_SERVER["SERVER_NAME"] = $argv[2];
$_SERVER["REMOTE_ADDR"] = $argv[3];

CLI:

( , , , . PHP , ... edit: , , , )

+3

All Articles