Home >Backend Development >PHP Tutorial >Understanding of php-cli environment

Understanding of php-cli environment

angryTom
angryTomforward
2020-01-19 17:35:062966browse

Understanding of php-cli environment

php-cli When I was looking at swoole, I saw that swoole_server can only be used in the php-cli environment, so what is the php-cli environment, so Baidu copied it online I think it is a useful introduction

Understanding of php-cli environment

What is the php_cli mode

php-cli is different from the php environment running on the web server. PHP can not only write front-end web pages, it can also be used to write back-end programs

Recommendation: "PHP Tutorial"

Advantages of php_cli mode

Use multiple processes. After the child process ends, the kernel will be responsible for recycling resources

2. Using multiple processes, the abnormal exit of the child process will not cause the entire process Thread to exit. The parent process will still have the opportunity to rebuild the process. .

3. A resident main process is only responsible for task distribution, and the logic is clearer.

4. Fully supports multi-threading

5. As above, scheduled tasks can be implemented

6. To develop desktop applications is to use PHP-CLI and GTK packages

7.Write shell scripts with php under Linux

How to run and run PHP CLI scripts

The first method is to use php -f /path/to/yourfile.php. Call the PHP CLI interpreter and pass parameters to the script. This method first requires setting the path of the php interpreter. Before running the CLI on the Windows platform, a command similar to path c:\php needs to be set. This also loses the meaning of the first line of the CLI script, so this method is not recommended.

The second method is to first run chmod line (similar to #! /usr/bin/php or PHP CLI interpreter location), and then execute it directly on the command line. This is the preferred method of CLI. It is recommended to use

This article comes from the php Chinese website, php tutorial column, welcome to learn!

The above is the detailed content of Understanding of php-cli environment. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.phpsong.com. If there is any infringement, please contact admin@php.cn delete

Related articles

See more