The following is an example of how php can obtain the linux command result. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the following small series to bring you an example of php getting linux command results. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at it with Xiaobian.
What should I do if I want to obtain the IP address of the etho Nic in the php command line?
Public function get_server_ip () {if (PHP_SAPI = 'cli ') {$ buffer = ""; $ handle = popen ("ifconfig eth0 | grep 'inet addr '| awk-F' [:]'' {print $13}' ", 'r'); while (! Feof ($ handle) {$ buffer. = fgets ($ handle);} pclose ($ handle); $ server_ip = rtrim ($ buffer);} else {if (isset ($ _ SERVER )) {if ($ _ SERVER ['server _ ADDR ']) {$ server_ip = $ _ SERVER ['server _ ADDR'];} else {$ server_ip = $ _ SERVER ['Local _ ADDR '] ;}} else {$ server_ip = getenv ('server _ ADDR') ;}} return $ server_ip ;}
The above is the details of the instance code for php to obtain the linux command result. For more information, see other related articles in the first PHP community!