PHPCLI mode introduction and tutorial

Source: Internet
Author: User
Tags php cli
Look at the full name to know, php-cli is phpCommandLineInterface abbreviation, that is, PHP command line interface, in windows and linux are support PHP-CLI mode, in fact, the two, I used to write text

Look at the full name to know, php-cli is php Command Line Interface short, that is, PHP Command Line Interface, in windows and linux are support PHP-CLI mode, in fact, the two, I have written articles before:
I. window: run the php program in the command line.
II. use crontab in linux to implement scheduled tasks
Advantages and application of PHP-CLI mode:

  • 1. multithreading is fully supported.
  • 2. as shown above, you can implement scheduled tasks.
  • 3. developing desktop applications is using PHP-CLI and GTK packages
  • 4. use php to write shell scripts in linux

In fact, the PHP runtime environment is far more than apache and cli, haha, such Aolserver, apache, apache2filter, apache2handler, caudium, cgi (until PHP 5.3), cgi-fcgi, cli, continuity, embed, isapi, litespeed, milter, nsapi, phttpd, pi3web, roxen, thttpd, tux, and webjames.

You can use php_sapi_name () to check the code:


 

I run the result on the browser:
On windows cmd, I run:
Use standard input and output:

STDINStandard input device

STDOUTStandard output device

STDERRStandard error device

You can see the result of running the following program:


  

Run:
Use the command line independent variable:
Php cli has two special variables to achieve this purpose: one is the $ argv variable, which saves the parameters passed to the PHP script as separate array elements through the command line; the other is the $ argc variable, which is used to save the number of elements in the $ argv array.
You can run:


   

Result:
Use php cli to pass script parameters:
See parameters:


Parameters Description
- Interactive Run of Run interactively
-C Path: Read the php. ini file from path.
-N Run without reading the php. ini file.
-M List compiled modules
-I Display PHP build information
-L Check the syntax of the PHP script
-S Display source code in color
-W Displays the source code after the annotation is removed.
-H Show Help




So far, I have a certain understanding of PHP CLI, if readers want to learn more, please refer to the official manual: http://php.net/manual/zh/features.commandline.php

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.