Php instance code for obtaining linux command results

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.