php获取linux命令结果的实例
2019/10/10/17:44:41 阅读:1883 来源:谷歌SEO算法 标签:
发外链
- publicfunctionget_server_ip(){
- if(PHP_SAPI==='cli'){
- $buffer="";
- $handle=popen("ifconfigeth0|grep'inetaddr'|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'];
- }//phpfensi.com
- }else{
- $server_ip=getenv('SERVER_ADDR');
- }
- }
- return$server_ip;
- }
热门评论