In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the example analysis of the PHP command line model, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Brief introduction of php_cli mode
Php-cli is the abbreviation of php Command Line Interface, as its name implies, that is, the interface through which php runs on the command line, which is different from the php environment (php-cgi, isapi, etc.) running on Web servers. That is to say, php can not only write foreground web pages, it can also be used to write background programs. PHP's CLI shell script applies to all the advantages of PHP, making it possible to create either scripts or systems or even servers with GUI applications! Note: php_cli mode is supported in both windows and linux
PHP-cli application scenarios:
1. Multithreaded application
The benefits in this respect, to quote Brother Bird:
Advantages:
1. Using multiple processes, after the child process ends, the kernel will be responsible for recycling resources
two。 With multiple processes, the abnormal exit of a child process does not cause the entire process Thread to exit. The parent process also has the opportunity to rebuild the process.
3. A resident main process, only responsible for task distribution, the logic is clearer.
Multithreading of php-Yes, it is the multithreaded application of php, although it is generally believed that php does not have multithreading (curl is simulated multithreading rather than real), but php in php_cli mode is completely multithreaded. At this point, php belongs to a daemon of linux. When I wrote "PHP multithread batch Collection and download Beauty Images (continued)", although curl is used to simulate multithreading in the collection program, the program will be interrupted due to execution timeout or memory abort during browser execution (it takes several attempts to be completely successful), but if you execute in php-cli mode, you will find that this program executes very quickly. The advantages of php multithreading execution have been thoroughly demonstrated.
Note: this multithreading method is not very mature and is not suitable for large-scale generation applications. It is OK to use it occasionally.
two。 Regular execution of php programs
Previously, I summarized three ways of "PHP regularly executing scheduled tasks". One of them is cron, which uses linux, so how to execute php programs regularly? Please read the following text
3. Develop desktop programs
You can do graphical user interface (GUI) applications using PHP in your Windows or Linux! All you need is a command line interface for PHP and a packet of GTK. This will allow you to build real portable graphical user interface applications (hehe, you only know that php can do desktop programs, but now you know that you are using php_cli mode), and you don't need to learn anything else.
4. Write shell scripts for PHP
What if you don't know how to use bash shell, Perl, etc., but you need some scripts to execute? At this time, you can use the familiar php to write shell scripts, at this time you suddenly feel that PHP is not too powerful! -- really achieve a language and develop it everywhere!
How to use PHP_CLI
The following execution methods of win:
Suppose php.exe in D:xamppphp, the dos command can be executed in this way:
The copy code is as follows:
D:\ xamppphpphp.exe D:\ xampphtdocstest.php
You can execute the test.php file. It is recommended that the xampp integration environment under the win platform is really N times more powerful than wamp. This integration package can directly enter dos mode.
Use of php_cli under linux
First, find the path where you installed php. Take me as an example:
Php is installed under the path / usr/local/php/bin/php
The copy code is as follows:
/ usr/local/php/bin/php / usr/local/apache/htdocs/a.php
You can execute a. Php file
PHP_CLI programming needs to know
How do I detect that the environment supports php_cli mode?
The copy code is as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.