PHP系统命令函数使用分析

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

function execute($cmd) {
     $res = '';
     if ($cmd) {
         if(function_exists('system')) {
             @ob_start();
             @system($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('passthru')) {
             @ob_start();
             @passthru($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('shell_exec')) {
             $res = @shell_exec($cmd);
         } elseif(function_exists('exec')) {
             @exec($cmd,$res);
             $res = join(“\n",$res);
         } elseif(@is_resource($f = @popen($cmd,"r"))) {
             $res = '';
             while(!@feof($f)) {
                 $res .= @fread($f,1024);
             }
             @pclose($f);
         }
     }
     return $res;
 }

相关文章

PHP CURL获取返回值的方法

在CURL中有一个参数 CURLOPT_RETURNTRANSFER :复制代码 代码如下:curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);默认是...

php上的memcache和memcached两个pecl库

之前尝试用的是memcache,后来发现memcached支持setMulti方法,准备转向使用memcached库了。 (试了下,实际上,memcache从支持多值set,但文档上还没...

php采集时被封ip的解决方法

在网上找了一些资料都没有找到,功夫不负有心人啊,在找的时侯有一个人提到了用搜索引擎爬虫蜘蛛的USERAGENT。虽然只提到一点点我还是想到了,列出我的解决方法, 1.使用Snoopy或c...

php基本函数汇总

1.统计数组元素个数 $arr = array( '1011,1003,1008,1001,1000,1004,1012', '1009', '1011,1003...

php实现数组按拼音顺序排序的方法 原创

本文实例讲述了php实现数组按拼音顺序排序的方法。分享给大家供大家参考,具体如下: 一、问题: 给定数组要求实现按照其汉字首字母排序: $pinyin = array( arra...