What is the difference between executing php from command line and from HTTP? Do they use the same executable such as (php.exe or php-cgi.exe ( Apache or IIS ))? Do the r
Though this question is very old, I'd like to extend @ Bob Fanger's a bit.
Running php files from the command line is quite trivial, you only have to keep in mind that there are some differences from running the file on a web server or on a servers command line interface:
No Cookies available
No $_GET
, $_POST
, $_SESSION
available
But you can use $argv
to get parameters passed as an argument to the command. The first value is allways the file name.
For example taken this file:
called like this:
user@ubuntu:$ /usr/bin/php /home/user/file.php foo bar
would give you this output:
array(4) {
[0]=>
string(8) "file.php"
[1]=>
string(3) "foo"
[2]=>
string(3) "bar"
}
Full file paths from your servers root required
You will need to provide the full paths to your files ( e.g. for include()
, require()
, file_get_contents()
, ... ), even though they might be in the same folder.
different user/permission settings
the files aren't getting executed by www-data
user, but by the user you are logged in into your machine. This affects all your file's function calls that effect the machines file system, ( e.g. mkdir()
, include()
, ... ) so you have to make sure to give appropriate permission to that user.