Home > Article > Backend Development > PHP command line usage introductory example tutorial, PHP command line example tutorial_PHP tutorial
The examples in this article describe the usage of php command line and are shared with everyone for your reference. The specific usage analysis is as follows:
Php is a very popular web server-side scripting language. In fact, php can not only play an important role in the web server. It can also be executed from the command line.
In this article, the author introduces how to use php in the command line.
1. Check the version and configuration of php
Enter php -v on the command line to view the current php version.
2. Run the php program in the command line
Running php from the command line is very easy. But there are some precautions that you need to understand. Server variables such as $_SESSION cannot be used in the command line, and other code runs exactly the same as in the web server^_^.
One of the benefits of executing php files on the command line is that you can execute some scheduled tasks through scripts. No need to go through the web server^_^.
Of course, we can also debug the code directly in php: enter the php -r command, and a ">" symbol will appear. This means that you have entered the PHP shell and can write code directly and execute it.
Without executing code, we can detect syntax errors in php files from the command line.
echo
'ddd'
;
style="color: #0000BB">?>
4. View the php manual
Starting from php5.1.2, programmers can view the manual on the php command line and enter php –rf function. A syntax introduction to the function will be printed
Is there any error message? Check the security level of php.ini and see if the exec function is restricted
Either PHP is not installed in your system; or your PHP file has syntax errors.
Use: php -v command first to see if PHP version information will be displayed. If not, it means PHP installation An error occurred;
If there is no error, write a xx.php file with the content: Then save it and execute php -f xx. php command to see if it is running correctly.