查看: 439|回复: 0

communication备份

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2025-5-25 18:24:55 | 显示全部楼层 |阅读模式
代码:

  1. <?php

  2. namespace addons\carplate\library;

  3. class Communication
  4. {

  5.     /**
  6.      * 模拟 http 请求
  7.      *
  8.      * @param string $url     请求URL地址
  9.      * @param string $post    请求数据
  10.      * @param array  $extra   header 参数
  11.      * @param int    $timeout 超时时间
  12.      *
  13.      * @return array http响应封装信息或错误信息
  14.      */
  15.     public function ihttp_request($url, $post = '', $extra = array(), $timeout = 60) {
  16.             //timeout为0时,相当于是非阻塞异步请求
  17.             //curl不支持timeout为0的情况,需要使用fsockopen来处理
  18.             if (function_exists('curl_init') && function_exists('curl_exec') && $timeout > 0) {
  19.                     $ch = $this->ihttp_build_curl($url, $post, $extra, $timeout);
  20.                     if ($this->is_error($ch)) {
  21.                             return $ch;
  22.                     }
  23.                     $data = curl_exec($ch);
  24.                     $status = curl_getinfo($ch);
  25.                     $errno = curl_errno($ch);
  26.                     $error = curl_error($ch);
  27.                     curl_close($ch);
  28.                     if ($errno || empty($data)) {
  29.                             return $this->error($errno, $error);
  30.                     } else {
  31.                             return $this->ihttp_response_parse($data);
  32.                     }
  33.             }
  34.             $urlset = $this->ihttp_parse_url($url, true);
  35.             if (!empty($urlset['ip'])) {
  36.                     $urlset['host'] = $urlset['ip'];
  37.             }
  38.    
  39.             $body = $this->ihttp_build_httpbody($url, $post, $extra);
  40.    
  41.             if ('https' == $urlset['scheme']) {
  42.                     $fp = $this->ihttp_socketopen('ssl://' . $urlset['host'], $urlset['port'], $errno, $error);
  43.             } else {
  44.                     $fp = $this->ihttp_socketopen($urlset['host'], $urlset['port'], $errno, $error);
  45.             }
  46.             stream_set_blocking($fp, $timeout > 0 ? true : false);
  47.             stream_set_timeout($fp, ini_get('default_socket_timeout'));
  48.             if (!$fp) {
  49.                     return $this->error(1, $error);
  50.             } else {
  51.                     fwrite($fp, $body);
  52.                     $content = '';
  53.                     if ($timeout > 0) {
  54.                             while (!feof($fp)) {
  55.                                     $content .= fgets($fp, 512);
  56.                             }
  57.                     }
  58.                     fclose($fp);
  59.    
  60.                     return $this->ihttp_response_parse($content, true);
  61.             }
  62.     }
  63.    
  64.     /**
  65.      * 封装的 GET 请求方法.
  66.      *
  67.      * @param string $url 请求URL地址
  68.      *
  69.      * @return array
  70.      */
  71.     public function ihttp_get($url) {
  72.             return $this->ihttp_request($url);
  73.     }
  74.    
  75.     /**
  76.      * 封装的POST请求方法.
  77.      *
  78.      * @param string $url  请求URL地址
  79.      * @param array  $data 请求数据
  80.      *
  81.      * @return array
  82.      */
  83.     public function ihttp_post($url, $data) {
  84.             $headers = array('Content-Type' => 'application/x-www-form-urlencoded');
  85.    
  86.             return $this->ihttp_request($url, $data, $headers);
  87.     }
  88.    
  89.     /**
  90.      * 非阻塞并发请求多个URL地址
  91.      *
  92.      * @param array $urls    请求多个地址数组
  93.      * @param array $posts   请求多个地址对应的POST数据
  94.      *                       二维数据组时,需要与URL键值一一对应,每个请求不同的POST数据
  95.      *                       一维数组时,每个请求使用此数据
  96.      * @param array $extra   同 ihttp_request
  97.      * @param int   $timeout 同 ihttp_request
  98.      *
  99.      * @return array 返回结果与url键值对应结果数组
  100.      */
  101.     public function ihttp_multi_request($urls, $posts = array(), $extra = array(), $timeout = 60) {
  102.             if (!is_array($urls)) {
  103.                     return $this->error(1, '请使用ihttp_request函数');
  104.             }
  105.             $curl_multi = curl_multi_init();
  106.             $curl_client = $response = array();
  107.    
  108.             foreach ($urls as $i => $url) {
  109.                     if (isset($posts[$i]) && is_array($posts[$i])) {
  110.                             $post = $posts[$i];
  111.                     } else {
  112.                             $post = $posts;
  113.                     }
  114.                     if (!empty($url)) {
  115.                             $curl = $this->ihttp_build_curl($url, $post, $extra, $timeout);
  116.                             if ($this->is_error($curl)) {
  117.                                     continue;
  118.                             }
  119.                             if (CURLM_OK === curl_multi_add_handle($curl_multi, $curl)) {
  120.                                     //存到数据组中,方便之后获取结果
  121.                                     $curl_client[] = $curl;
  122.                             }
  123.                     }
  124.             }
  125.             if (!empty($curl_client)) {
  126.                     $active = null;
  127.                     do {
  128.                             $mrc = curl_multi_exec($curl_multi, $active);
  129.                     } while (CURLM_CALL_MULTI_PERFORM == $mrc);
  130.    
  131.                     while ($active && CURLM_OK == $mrc) {
  132.                             do {
  133.                                     $mrc = curl_multi_exec($curl_multi, $active);
  134.                             } while (CURLM_CALL_MULTI_PERFORM == $mrc);
  135.                     }
  136.             }
  137.    
  138.             foreach ($curl_client as $i => $curl) {
  139.                     $response[$i] = curl_multi_getcontent($curl);
  140.                     curl_multi_remove_handle($curl_multi, $curl);
  141.             }
  142.             curl_multi_close($curl_multi);
  143.    
  144.             return $response;
  145.     }
  146.    
  147.     public function ihttp_socketopen($hostname, $port, &$errno, &$errstr, $timeout = 15) {
  148.             $fp = '';
  149.             $port = !empty($port) ? $port : 80;
  150.             if (function_exists('fsockopen')) {
  151.                     $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
  152.             } elseif (function_exists('pfsockopen')) {
  153.                     $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
  154.             } elseif (function_exists('stream_socket_client')) {
  155.                     $fp = @stream_socket_client($hostname . ':' . $port, $errno, $errstr, $timeout);
  156.             }
  157.    
  158.             return $fp;
  159.     }
  160.    
  161.     /**
  162.      * 对请求得到的数据的进行分析和封装.
  163.      *
  164.      * @param string $data
  165.      * @param bool   $chunked
  166.      *
  167.      * @return array error 或 $data 的封装
  168.      */
  169.     public function ihttp_response_parse($data, $chunked = false) {
  170.             $rlt = array();
  171.    
  172.             $pos = strpos($data, "\r\n\r\n");
  173.             $split1[0] = substr($data, 0, $pos);
  174.             $split1[1] = substr($data, $pos + 4, strlen($data));
  175.    
  176.             $split2 = explode("\r\n", $split1[0], 2);
  177.             preg_match('/^(\S+) (\S+) (.*)$/', $split2[0], $matches);
  178.             $rlt['code'] = !empty($matches[2]) ? $matches[2] : 200;
  179.             $rlt['status'] = !empty($matches[3]) ? $matches[3] : 'OK';
  180.             $rlt['responseline'] = !empty($split2[0]) ? $split2[0] : '';
  181.             $header = !empty($split2[1]) ? explode("\r\n", $split2[1]) : array();
  182.             $isgzip = false;
  183.             $ischunk = false;
  184.             foreach ($header as $v) {
  185.                     $pos = strpos($v, ':');
  186.                     $key = substr($v, 0, $pos);
  187.                     $value = trim(substr($v, $pos + 1));
  188.                     if (isset($rlt['headers'][$key]) && is_array($rlt['headers'][$key])) {
  189.                             $rlt['headers'][$key][] = $value;
  190.                     } elseif (!empty($rlt['headers'][$key])) {
  191.                             $temp = $rlt['headers'][$key];
  192.                             unset($rlt['headers'][$key]);
  193.                             $rlt['headers'][$key][] = $temp;
  194.                             $rlt['headers'][$key][] = $value;
  195.                     } else {
  196.                             $rlt['headers'][$key] = $value;
  197.                     }
  198.                     if (!$isgzip && 'content-encoding' == strtolower($key) && 'gzip' == strtolower($value)) {
  199.                             $isgzip = true;
  200.                     }
  201.                     if (!$ischunk && 'transfer-encoding' == strtolower($key) && 'chunked' == strtolower($value)) {
  202.                             $ischunk = true;
  203.                     }
  204.             }
  205.             if ($chunked && $ischunk) {
  206.                     $rlt['content'] = $this->ihttp_response_parse_unchunk($split1[1]);
  207.             } else {
  208.                     $rlt['content'] = $split1[1];
  209.             }
  210.             if ($isgzip && function_exists('gzdecode')) {
  211.                     $rlt['content'] = gzdecode($rlt['content']);
  212.             }
  213.    
  214.             $rlt['meta'] = $data;
  215.             if ('100' == $rlt['code']) {
  216.                     return $this->ihttp_response_parse($rlt['content']);
  217.             }
  218.    
  219.             return $rlt;
  220.     }
  221.    
  222.     public function ihttp_response_parse_unchunk($str = null) {
  223.             if (!is_string($str) or strlen($str) < 1) {
  224.                     return false;
  225.             }
  226.             $eol = "\r\n";
  227.             $add = strlen($eol);
  228.             $tmp = $str;
  229.             $str = '';
  230.             do {
  231.                     $tmp = ltrim($tmp);
  232.                     $pos = strpos($tmp, $eol);
  233.                     if (false === $pos) {
  234.                             return false;
  235.                     }
  236.                     $len = hexdec(substr($tmp, 0, $pos));
  237.                     if (!is_numeric($len) or $len < 0) {
  238.                             return false;
  239.                     }
  240.                     $str .= substr($tmp, ($pos + $add), $len);
  241.                     $tmp = substr($tmp, ($len + $pos + $add));
  242.                     $check = trim($tmp);
  243.             } while (!empty($check));
  244.             unset($tmp);
  245.    
  246.             return $str;
  247.     }
  248.    
  249.     /**
  250.      * 格式化请求URL.
  251.      *
  252.      * @param string $url              要格式化检查的URL
  253.      * @param bool   $set_default_port 是否根据协议指定默认端口
  254.      *
  255.      * @return array
  256.      */
  257.     public function ihttp_parse_url($url, $set_default_port = false) {
  258.             if (empty($url)) {
  259.                     return $this->error(1);
  260.             }
  261.             $urlset = parse_url($url);
  262.             if (!empty($urlset['scheme']) && !in_array($urlset['scheme'], array('http', 'https'))) {
  263.                     return $this->error(1, '只能使用 http 及 https 协议');
  264.             }
  265.             if (empty($urlset['path'])) {
  266.                     $urlset['path'] = '/';
  267.             }
  268.             if (!empty($urlset['query'])) {
  269.                     $urlset['query'] = "?{$urlset['query']}";
  270.             }
  271.             if (strexists($url, 'https://') && !extension_loaded('openssl')) {
  272.                     if (!extension_loaded('openssl')) {
  273.                             return $this->error(1, '请开启您PHP环境的openssl', '');
  274.                     }
  275.             }
  276.             if (empty($urlset['host'])) {
  277.                     $current_url = parse_url($GLOBALS['_W']['siteroot']);
  278.                     $urlset['host'] = $current_url['host'];
  279.                     $urlset['scheme'] = $current_url['scheme'];
  280.                     $urlset['path'] = $current_url['path'] . 'web/' . str_replace('./', '', $urlset['path']);
  281.                     $urlset['ip'] = '127.0.0.1';
  282.             } elseif (!$this->ihttp_allow_host($urlset['host'])) {
  283.                     return $this->error(1, 'host 非法');
  284.             }
  285.    
  286.             if ($set_default_port && empty($urlset['port'])) {
  287.                     $urlset['port'] = 'https' == $urlset['scheme'] ? '443' : '80';
  288.             }
  289.    
  290.             return $urlset;
  291.     }
  292.    
  293.     /**
  294.      *  是否允许指定host访问.
  295.      *
  296.      * @param $host
  297.      *
  298.      * @return bool
  299.      */
  300.     public function ihttp_allow_host($host) {
  301.             global $_W;
  302.             if (strexists($host, '@')) {
  303.                     return false;
  304.             }
  305.             $pattern = '/^(10|172|192|127)/';
  306.             if (preg_match($pattern, $host) && isset($_W['setting']['ip_white_list'])) {
  307.                     $ip_white_list = $_W['setting']['ip_white_list'];
  308.                     if ($ip_white_list && isset($ip_white_list[$host]) && !$ip_white_list[$host]['status']) {
  309.                             return false;
  310.                     }
  311.             }
  312.    
  313.             return true;
  314.     }
  315.    
  316.     /**
  317.      * 创建一个curl请求对象
  318.      * 参数同 ihttp_request.
  319.      *
  320.      * @return curl response
  321.      */
  322.     public function ihttp_build_curl($url, $post, $extra, $timeout) {
  323.             if (!function_exists('curl_init') || !function_exists('curl_exec')) {
  324.                     return $this->error(1, 'curl扩展未开启');
  325.             }
  326.    
  327.             $urlset = $this->ihttp_parse_url($url);
  328.             if ($this->is_error($urlset)) {
  329.                     return $urlset;
  330.             }
  331.    
  332.             if (!empty($urlset['ip'])) {
  333.                     $extra['ip'] = $urlset['ip'];
  334.             }
  335.    
  336.             $ch = curl_init();
  337.             if (!empty($extra['ip'])) {
  338.                     $extra['Host'] = $urlset['host'];
  339.                     $urlset['host'] = $extra['ip'];
  340.                     unset($extra['ip']);
  341.             }
  342.             curl_setopt($ch, CURLOPT_URL, $urlset['scheme'] . '://' . $urlset['host'] . (empty($urlset['port']) || '80' == $urlset['port'] ? '' : ':' . $urlset['port']) . $urlset['path'] . (!empty($urlset['query']) ? $urlset['query'] : ''));
  343.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  344.             @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  345.             curl_setopt($ch, CURLOPT_HEADER, 1);
  346.             @curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  347.             if ($post) {
  348.                     if (is_array($post)) {
  349.                             $filepost = false;
  350.                             // 5.6版本后,'@'上传,使用CURLFile替代
  351.                             foreach ($post as $name => &$value) {
  352.                                     if (version_compare(phpversion(), '5.5') >= 0 && is_string($value) && '@' == substr($value, 0, 1)) {
  353.                                             $post[$name] = new CURLFile(ltrim($value, '@'));
  354.                                     }
  355.                                     if ((is_string($value) && '@' == substr($value, 0, 1)) || (class_exists('CURLFile') && $value instanceof CURLFile)) {
  356.                                             $filepost = true;
  357.                                     }
  358.                             }
  359.                             if (!$filepost) {
  360.                                     $post = http_build_query($post);
  361.                             }
  362.                     }
  363.                     curl_setopt($ch, CURLOPT_POST, 1);
  364.                     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  365.             }
  366.             if (!empty($GLOBALS['_W']['config']['setting']['proxy'])) {
  367.                     $urls = parse_url($GLOBALS['_W']['config']['setting']['proxy']['host']);
  368.                     if (!empty($urls['host'])) {
  369.                             curl_setopt($ch, CURLOPT_PROXY, "{$urls['host']}:{$urls['port']}");
  370.                             $proxytype = 'CURLPROXY_' . strtoupper($urls['scheme']);
  371.                             if (!empty($urls['scheme']) && defined($proxytype)) {
  372.                                     curl_setopt($ch, CURLOPT_PROXYTYPE, constant($proxytype));
  373.                             } else {
  374.                                     curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  375.                                     curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  376.                             }
  377.                             if (!empty($GLOBALS['_W']['config']['setting']['proxy']['auth'])) {
  378.                                     curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['_W']['config']['setting']['proxy']['auth']);
  379.                             }
  380.                     }
  381.             }
  382.             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  383.             curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  384.             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  385.             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  386.             curl_setopt($ch, CURLOPT_SSLVERSION, 1);
  387.             if (defined('CURL_SSLVERSION_TLSv1')) {
  388.                     curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
  389.             }
  390.             curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
  391.             if (!empty($extra) && is_array($extra)) {
  392.                     $headers = array();
  393.                     foreach ($extra as $opt => $value) {
  394.                             if (strexists($opt, 'CURLOPT_')) {
  395.                                     curl_setopt($ch, constant($opt), $value);
  396.                             } elseif (is_numeric($opt)) {
  397.                                     curl_setopt($ch, $opt, $value);
  398.                             } else {
  399.                                     $headers[] = "{$opt}: {$value}";
  400.                             }
  401.                     }
  402.                     if (!empty($headers)) {
  403.                             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  404.                     }
  405.             }
  406.    
  407.             return $ch;
  408.     }
  409.    
  410.     public function ihttp_build_httpbody($url, $post, $extra) {
  411.             $urlset = $this->ihttp_parse_url($url, true);
  412.             if ($this->is_error($urlset)) {
  413.                     return $urlset;
  414.             }
  415.    
  416.             if (!empty($urlset['ip'])) {
  417.                     $extra['ip'] = $urlset['ip'];
  418.             }
  419.    
  420.             $body = '';
  421.             if (!empty($post) && is_array($post)) {
  422.                     $filepost = false;
  423.                     $boundary = $this->random(40);
  424.                     foreach ($post as $name => &$value) {
  425.                             if ((is_string($value) && '@' == substr($value, 0, 1)) && file_exists(ltrim($value, '@'))) {
  426.                                     $filepost = true;
  427.                                     $file = ltrim($value, '@');
  428.    
  429.                                     $body .= "--$boundary\r\n";
  430.                                     $body .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . basename($file) . '"; Content-Type: application/octet-stream' . "\r\n\r\n";
  431.                                     $body .= file_get_contents($file) . "\r\n";
  432.                             } else {
  433.                                     $body .= "--$boundary\r\n";
  434.                                     $body .= 'Content-Disposition: form-data; name="' . $name . '"' . "\r\n\r\n";
  435.                                     $body .= $value . "\r\n";
  436.                             }
  437.                     }
  438.                     if (!$filepost) {
  439.                             $body = http_build_query($post, '', '&');
  440.                     } else {
  441.                             $body .= "--$boundary\r\n";
  442.                     }
  443.             }
  444.    
  445.             $method = empty($post) ? 'GET' : 'POST';
  446.             $fdata = "{$method} {$urlset['path']}{$urlset['query']} HTTP/1.1\r\n";
  447.             $fdata .= "Accept: */*\r\n";
  448.             $fdata .= "Accept-Language: zh-cn\r\n";
  449.             if ('POST' == $method) {
  450.                     $fdata .= empty($filepost) ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data; boundary=$boundary\r\n";
  451.             }
  452.             $fdata .= "Host: {$urlset['host']}\r\n";
  453.             $fdata .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\n";
  454.             if (function_exists('gzdecode')) {
  455.                     $fdata .= "Accept-Encoding: gzip, deflate\r\n";
  456.             }
  457.             $fdata .= "Connection: close\r\n";
  458.             if (!empty($extra) && is_array($extra)) {
  459.                     foreach ($extra as $opt => $value) {
  460.                             if (!strexists($opt, 'CURLOPT_')) {
  461.                                     $fdata .= "{$opt}: {$value}\r\n";
  462.                             }
  463.                     }
  464.             }
  465.             if ($body) {
  466.                     $fdata .= 'Content-Length: ' . strlen($body) . "\r\n\r\n{$body}";
  467.             } else {
  468.                     $fdata .= "\r\n";
  469.             }
  470.    
  471.             return $fdata;
  472.     }
  473.    
  474.     /**
  475.      * 检测数组是否产生错误.
  476.      * @param mixed $data
  477.      * @return boolean
  478.      */
  479.     public function is_error($data) {
  480.             if (empty($data) || !is_array($data) || !array_key_exists('errno', $data) || (array_key_exists('errno', $data) && 0 == $data['errno'])) {
  481.                     return false;
  482.             } else {
  483.                     return true;
  484.             }
  485.     }
  486.    
  487.     /**
  488.      * 构造错误数组.
  489.      * @param int    $errno   错误码,0为无任何错误
  490.      * @param string $message 错误信息
  491.      * @return array
  492.      */
  493.     public function error($errno, $message = '') {
  494.             return array(
  495.                     'errno' => $errno,
  496.                     'message' => $message,
  497.             );
  498.     }
  499.    
  500.     /**
  501.      * 获取随机字符串.
  502.      * @param number $length  字符串长度
  503.      * @param bool   $numeric 是否为纯数字
  504.      * @return string
  505.      */
  506.     public function random($length, $numeric = false) {
  507.             $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  508.             $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  509.             if ($numeric) {
  510.                     $hash = '';
  511.             } else {
  512.                     $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
  513.                     --$length;
  514.             }
  515.             $max = strlen($seed) - 1;
  516.             for ($i = 0; $i < $length; ++$i) {
  517.                     $hash .= $seed[mt_rand(0, $max)];
  518.             }
  519.    
  520.             return $hash;
  521.     }
  522.    
  523.     /**
  524.      * 记录运行日志.
  525.      *
  526.      * @param string|array $log         日志内容
  527.      * @param string       $type        日志类型
  528.      * @param string       $filename    日志文件名称
  529.      * @param bool         $includePost 是否记录POST信息
  530.      *
  531.      * @return array|boolean
  532.      */
  533.     public function logging_run($log, $type = 'trace', $filename = 'run') {
  534.             global $_W;
  535.             $filename = IA_ROOT . '/data/logs/' . $filename . '_' . date('Ymd') . '.php';
  536.    
  537.             load()->func('file');
  538.             mkdirs(dirname($filename));
  539.    
  540.             $logFormat = '%date %type %user %url %context';
  541.             if (!empty($GLOBALS['_POST'])) {
  542.                     $context[] = logging_implode($GLOBALS['_POST']);
  543.             }
  544.    
  545.             if (is_array($log)) {
  546.                     $context[] = logging_implode($log);
  547.             } else {
  548.                     $context[] = preg_replace('/[ \t\r\n]+/', ' ', $log);
  549.             }
  550.    
  551.             $log = str_replace(explode(' ', $logFormat), array(
  552.                     '[' . date('Y-m-d H:i:s', $_W['timestamp']) . ']',
  553.                     $type,
  554.                     $_W['username'],
  555.                     $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'],
  556.                     implode("\n", $context),
  557.             ), $logFormat);
  558.             if (file_exists($filename)) {
  559.                     $log =  $log . "\r\n";
  560.             } else {
  561.                     $log = "<?php exit;?>\r\n" . $log . "\r\n";
  562.             }
  563.             file_put_contents($filename, $log, FILE_APPEND);
  564.             return true;
  565.     }
  566.    
  567.     public function logging_implode($array, $skip = array()) {
  568.             $return = '';
  569.             if (is_array($array) && !empty($array)) {
  570.                     foreach ($array as $key => $value) {
  571.                             if (empty($skip) || !in_array($key, $skip, true)) {
  572.                                     if (is_array($value)) {
  573.                                             $return .= $key . '={' . $this->logging_implode($value, $skip) . '}; ';
  574.                                     } else {
  575.                                             $return .= "$key=$value; ";
  576.                                     }
  577.                             }
  578.                     }
  579.             }
  580.    
  581.             return $return;
  582.     }
  583. }
复制代码


道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部