laravel百万级数据导出

测试结果

先上测试结果8核16G的服务器

字段数消耗时间/秒数量/万CPU增加/百分百
单表42510010-30
单表连7张表2131810-20

安装

1.composer安装

安装到项目

composer require viest/php-ext-xlswriter-ide-helper

2.php扩展安装,Centos环境

php扩展安装

  • 1.参考,这是官方Ubuntu的安装方法
下载

查看最新版

wget https://pecl.php.net/get/xlswriter-1.3.3.2.tgz

解压
tar  zxvf xlswriter-1.3.3.2.tgz 
进入目录
cd xlswriter-1.3.3.2
编译

注意php目录替换为自己服务器上php安装的目录

php目录/bin/phpize && ./configure --with-php-config=php目录/bin/php-config --enable-reader
安装
make && make install
安装成功返回
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     php目录/lib/php/extensions/no-debug-non-zts-20160303/

修改php.ini
extension = php目录/lib/php/extensions/no-debug-non-zts-20160303/xlswriter.so

3.官方代码示例

$config = ['path' => '/home/viest'];
$excel  = new \Vtiful\Kernel\Excel($config);

// fileName 会自动创建一个工作表,你可以自定义该工作表名称,工作表名称为可选参数
$filePath = $excel->fileName('tutorial01.xlsx', 'sheet1')
    ->header(['Item', 'Cost'])
    ->data([
        ['Rent', 1000],
        ['Gas',  100],
        ['Food', 300],
        ['Gym',  50],
    ])
    ->output();

4.我封装的代码

安装
composer require pl/laravel-admin-api
文档
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值