• PHP上传大文件和处理大数据


    1. 上传大文件

            /* 以1.5M/秒的速度写入文件,防止一次过写入文件过大导致服务器出错(chy/20150327) */
            $is_large_file = false;
            if( strlen($xml_str)>=2097152 ){ //当文件大于2M
                $is_large_file = true;
                
                fwrite($fp, $pre, strlen($pre)); //写入头部
                $start = 0;
                while( $content=mb_strcut($xml_str,$start,1572864) ){
                    $start = $start + 1572864;
                    $writeResult = fwrite($fp, $content, strlen($content));
                    if( !$writeResult ){
                        unlink($filename);
                        break;
                    }
                    sleep(1);
                    unset($content);
                }
                unset($xml_str);
                fwrite($fp, $end, strlen($end)); //写入尾部
            }else{
                $content = $pre.$xml_str.$end;
                fwrite($fp, $content, strlen($content));
            }

    2. 处理大数据的加密

        //aes加密
        public function aesEncode_large($info) {
            //.....(省略部分代码)

        if(mcrypt_generic_init($cipher, $this->aesKey, $this->aesIv) != -1){ //$cipherText = mcrypt_generic($cipher, $beianInfo); //原普通的加密方式(chy/20150327) //处理大字符串加密。temp.text主要用于文件缓存(chy/20150327) $filename = B_ROOT."/admin/temp/temp.txt"; file_put_contents($filename,''); //将文件清空 $fp = fopen($filename, 'wb'); while( $content=mb_strcut($info,$start,104800) ){ $start = $start + 104800; $cipherTextCut = mcrypt_generic($cipher, $content); fwrite($fp, $cipherTextCut, strlen($cipherTextCut)); unset($cipherTextCut); unset($content); } mcrypt_generic_deinit($cipher); mcrypt_module_close($cipher); fclose($fp); return true; } else { return false; } }
  • 相关阅读:
    MORMOT数据库连接池
    TOleDBMSSQLConnectionProperties驱动MSSQL数据库
    mORMot访问远程数据库
    mormot 直接使用UNIDAC引擎操作数据库
    mormot 数据集和JSON互相转换
    Go -- 读取文件内容
    nginx -- 启动, 重启, 关闭
    JS -- 一篇文章掌握RequireJS常用知识
    用JS获取地址栏参数的方法(超级简单)
    git -- 忽略某个文件
  • 原文地址:https://www.cnblogs.com/chy1000/p/4372566.html
Copyright © 2020-2023  润新知