|
Using PHP As A Shell Scripting Language
Darrell Brogdon
As most of us already know, PHP is the best language for developing
dynamic web pages available today. Not many people are aware that it
can be used as a shell scripting language as well. While PHP as a
shell script isn't as robust as Bash or Perl it does have definite
advantages, especially if you're like me and are more proficient in
PHP than you are in Perl.
The requirements for using PHP as a shell language is that you must
compile PHP as a CGI binary instead of as an Apache module. There
are certain security issues related to this so please refer to the
PHP Manual when doing so.
Where the code is concerned, the only difference between a PHP
shell script and a regular PHP web page is the existence of the
standard shell call at the top of the script:
#!/usr/local/bin/php -q
We're using the
'-q' switch so that the HTTP headers are suppressed.
Also, you're still required to begin and end the script with the
standard PHP tags:
<?php ?>
So let's delve into the standard code sample we all know and love:
#!/usr/local/bin/php -q
<?php
print("Hello, world!\n");
?>
This, as most of you know already (about a billion times over)
will simply output to the screen "Hello, world!".
[ Next Page ]


