In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "use php to simulate the commonly used DOS command ping command method", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in-depth, together to study and learn "use php to simulate the commonly used DOS command ping command method"!
Use php to simulate our commonly used DOS command ping command method, here is mainly used is the php built-in function exec to call the system's ping command, so as to achieve the ping command function.
The copy code is as follows:
Note that using the exec function requires server support to call the system's built-in function. You can also use php built-in functions such as system to achieve this function. The php manual explains these two functions:
Exec-execute external programs
Syntax: string exec (string command [, array & output [, int & return_var]])
Description:
Exec () executes the given command command, but it doesn't output anything. It simply returns the last line from the result of the command. If you need to execute a command and get all the data from the command, you can use the function passthru ().
If the parameter array is given, the specified array will be filled with every line output by the command. Note: if the array already contains some elements, exec () will append it to the array. If you don't want this function to add elements, you can call unset () before passing the array to exec ().
If the arguments array and return_var are given, the status command returned for execution will be written to this variable.
Meaning: if you allow data from user input that can be passed to this function, you should use escapeshellcmd () to make sure that the user cannot trick the system to execute arbitrary commands.
Note: if you use this function to start a program and want to leave it while running in the background (background), you must make sure that the program's output is redirected to a file or some output stream, otherwise PHP will hang until the end of the program execution.
System-execute the external program and display the output
Syntax: string system (string command [, int & return_var])
Description:
System () executes the given command command and outputs the result. If the argument return_var is given, the status code for executing the command will be written to this variable.
Note: if you allow data from user input to be passed to this function, you should use escapeshellcmd () to make sure that the user cannot trick the system to execute arbitrary commands.
Note: if you use this function to start a program and want to leave it while running in the background (background), you must make sure that the program's output is redirected to a file or some output stream, otherwise PHP will hang until the end of the program execution.
Both of these are used to call system shell commands, with the following differences:
Exec can return all the results of execution to the $output function (array). $status is the state of execution. 0 is success and 1 is failure.
Systerm does not need to provide the $output function, it returns the result directly. Similarly, $return_var is the status code of execution, 0 is success, 1 is failure.
Exec example:
The copy code is as follows:
System example:
The copy code is as follows:
Thank you for your reading, the above is the content of "using php to simulate the commonly used DOS command ping command". After the study of this article, I believe you have a deeper understanding of the problem of using php to simulate the commonly used DOS command ping command method, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.