PHP command line command user guide, php command line user guide _ PHP Tutorial

Source: Internet
Author: User
PHP command line command instructions, php command line instructions. PHP command line Command Guide. php command line guide when a user opens the php page, the server executes the PHP command and sends the execution result to the user's browser, this is similar to the PHP command line command user guide, php command line User Guide

When a user opens the php page, the server executes the PHP command and sends the execution result to the user's browser, which is similar to ASP and CoildFusion, PHP can run on WINDOWS and multiple versions of UNIX. In addition to being able to operate on your page, PHP can also send HTTP headers.

You can set cookies, manage digital signatures, and redirect users, and provide excellent connectivity to other databases (as well as ODBC ), integrate various external libraries to parse XML in PDF documents. Do you still know that you can use the powerful functions of php to do something else? When running in an independent cgi mode, a php executable program is required. it has many command line parameters, some of which can be used for interesting purposes. below are all the php command line parameters, [] indicates that the table is dispensable. <> The table is required.

Use php [-q] [-h] [-s] [-v] [-I] [-f] | {[args...]}-q Quiet mode. No HTTP header is output.
-S converts php program files to HTML in color format (for example, the reserved words are green, the functions and variables are blue, the comments are yellow, and the strings are red.

-F reads and interprets the specified file.

-C reads the php. ini file in

-A Interactive operation

-D foo [= bar] defines the input item foo in ini as bar.

-E outputs additional information for debugging and performance analysis

-Z: call Zend extension file

-I php-related information

-H help itself.

1. use php-q file name. php to use the php program as a shell program,

2. use-s to html your php program. Isn't that easy?

3. use the odbc function of php to operate databases in shell commands.

Several common commands
1. View php version and configuration

Enter php-v in the command line to view the current php version.

 PHP 5.2.17(cli) (built: Feb 2 2011 11:19:21) 
 Copyright (c) 1997-2010 The PHP Group 
 Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies 
 with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies 
 with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator 

Other options include-m and-I. I will not give a column here.

-M displays the valid modules loaded by php.

-I: No phpinfo in html format is output.

You can use the-ini option to output the quantity and path information of the ini configuration file loaded by the current php.


2. run the php program in the command line.

It is very easy to run php from the command line. However, you need to know some precautions. Server variables such as $ _ SESSION cannot be used in the command line, and other code runs exactly the same as pai_^ on the web server.

<? Php echo "run php command line echo";?>

Save the above code as hello. php. Input php-f hello. php in the command line. The result is as follows:

Run php command line echo

One of the advantages of executing the php file in the command line is that you can execute some scheduled tasks through scripts. Instead of using the web server pai_^.

Of course, we can also directly debug the code in php: Enter the php-r command and a ">" symbol will appear. This indicates that you have entered the php shell and can directly write and execute the code.

<? php
  echo "Run php command line echo";

You can also use the php-a command to open the interactive mode and enter a line of code. php will output the result in real time.

3. check php syntax and highlight output

You do not need to execute the code. we can check the php file syntax errors in the command line.

 -bash-3.2$ php -l hello.php 

No syntax errors detected in hello. php

Programmers often need to highlight the php code as is and use php-s.

 -bash-3.2$ php -r ' 
 > for($i=0;$i<2;$i++){ 
 > echo "Number: {$i}\n"; 
 > } 
 > ' 
 Number: 0 
 Number: 1 

4. view the php Manual

Starting from php5.1.2, programmers can view the manual under the php command line and enter the php-rf function. The syntax of the function is printed.

 -bash-3.2$ php --rf strip_tags
 -bash-3.2$ php --rf strip_tags 
  Function [  function strip_tags ] { 
  - Parameters [2] { 
  Parameter #0 [  $str ] 
  Parameter #1 [  $allowable_tags ] 

When a user opens the php page, the server executes the PHP command and sends the execution result to the user's browser, which is similar...

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: 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.