Linux programming: Use PHP as a Shell script

Source: Internet
Author: User
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 ");
?>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.