php 大資料excel匯出 buffer配置

2021-10-04 02:21:37 字數 2420 閱讀 8065

原理:php開啟快取區輸出 --> php系統緩衝區(nginx, apache伺服器) --> 瀏覽器緩衝區

apache配置: httpd.conf

由於預設開啟了mod_cgi.so模組

在http.conf配置檔案最後一行加上, 表示設定緩衝區的位元組大小為0,一旦有php輸出,就立馬響應瀏覽器輸出

fcgidoutputbuffersize 0

注意,nginx也有設定buffer的大小

<?php

/** * 匯出大資料抽象類

*/abstract class largeexportabstract

/**第一行匯出

* @return array

*/public function beforerow()

/**資料匯出

* @param $row

* @return mixed

*/public function formatrow($row)

protected function outputstart()

protected function outputend()

/*** 建立io

*/protected function iostart()

/*** 關閉io

*/protected function ioend()

/*** 清空緩衝區, 內容進入下一層緩衝區

*/protected function flush()

/**向excel輸出一行資料

* @param $row

*/public function put($row)

/**匯出

* @param string $filename 可選,檔名

*/public function export($filename = '')

//建立乙個流式io

$this->iostart();

//資料查詢前向瀏覽器輸出

$beforerow = $this->beforerow();

if (!empty($beforerow))

//資料分批查詢

$this->getquery()->chunk((int)$this->chunknum, function ($rows)

unset($rows);

//php緩衝區釋放, 進入下一層緩衝區

$this->flush();

});//關閉io

$this->ioend();

}/**原樣輸出,防止小數匯出時為空 如數字5.00,本應匯出 5.00 ,實際匯出了 5

* @param $value

* @return string

*/public function totext($value)

}

<?php

/*查詢類服務

*/class rankstatisticservice

public function getquery()

}/**統計匯出

* class rankstatistic

*/class rankstatisticexport extends largeexportabstract

public function getquery()

public function beforerow()

public function formatrow($v)

期", //期數

$v->user_id, //會員id

$v->group_name, //會員手機號

$this->totext($v->mobile), //會員所屬分組

$v->vip_number, //開通權益會員數量

$v->user_rank, //排名

$v->reward_zh, //是否獲得獎勵

$v->reward_name, //獎品名稱

$v->addressdetail //收貨位址

];return $this->initrow($row);

}/**格式化匯出的資料

* @param $row

* @return array

*/protected function initrow($row)

return $row;

}}/*

客戶端呼叫

*/(new rankstatisticexport(1, )->export();

PHP資料匯出Excel

需要將php資料匯出exel 中,可以用phpexcel,但是也有更快的方法,但是會出現些小問題 比如 處理excel匯出 param datas array 設定 資料 param titlename string 設定head param title string 設定表頭 function e...

php匯出大資料csv

author 漫步雲端 header content type text html charset utf 8 class phpcsv public function settile title public function init fputcsv this fp,this sheethead...

POI 02 Excel大資料匯出

之前提及了 excel 大資料的讀取,現在我們再來了解下 excel 大資料的匯出 官方文件 sxssf streaming usermodel api 生成單個工作表 param rownums 行數 param columnnums 列數 param filepath excel儲存路徑 pub...