Contrary to popular belief, PHP is not just a web server language. PHP can also be used to create regular programs. PHP can be used to create GUI applications, shell scripts, and even daemons, among other things.
The boon is that all (or most) of the usual PHP libraries are available to your PHP CLI program too. MySQL, XML, etc. It's all (or mostly) still available.
Difference Between PHP and PHP CLI
There are some important differences between server-side PHP and PHP CLI. Here's a list of them:
1. There is no $_GET super global array.
2. There is no $_POST super global array.
3. There is no $_COOKIE super global array.
4. When you do a print, the output goes to the standard output and not a web browser.
5. You can get command line arguments via the $argv variable.
6. You can get the number of command line arguments via the $argc variable.
eg:
<?php
print('ARGC = ' . $argc ."\n\n");
foreach ($argv as $k=>$v) {
print("ARGV[$k] = $v\n");
}
?>
on command line
php test1.php apple orange banana pineapple
output
ARGC = 4
ARGV[0] = test1.php
ARGV[1] = apple
ARGV[2] = orange
ARGV[3] = banana
ARGV[4] = pineapple
Monday, March 10, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment