Linux programming: Use PHP as a Shell script-general Linux technology-Linux programming and kernel information. For details, see the following. We all know that PHP is a very good dynamic web page development language (fast speed, short development cycle ......). However, only a few people realize that PHP can also be a good language for writing Shell scripts. When PHP is used as a language for writing Shell scripts, it is not as powerful as Perl or Bash, but he has a good advantage, especially for people who are familiar with PHP but are not familiar with Perl.
To use PHP as the Shell scripting language, you must compile PHP as a binary CGI instead of the Apache mode. Compiling PHP to run in binary CGI Mode has some security issues. At first, you may feel uncomfortable with writing Shell scripts, but it will be better: the only difference between using PHP as a general dynamic Web writing language and using Shell scripting language is that a Shell script needs to explain the program path of this script in the first line of life.
We add the parameter "-1" after the PHP Execution file, so that PHP will not output HTTPHeader (if it still needs to be used as a dynamic Web page of the Web, then you need to use the header function to output HTTPHeader ). Of course, you still need to use the PHP start and end mark in the Shell script:
Now let's look at an example to better understand the use of PHP as a Shell scripting language:
CODE: Print ("Hello, world! N "); ?> |