PHP thinkphp5 分批匯出大批量資料

2021-10-01 22:45:21 字數 1579 閱讀 3641

namespace

;/**

* 檔案匯出(zip格式)

*/class

fileexport

return self:

:$initialize;}

/** * 設定臨時及匯出檔名

*/public

function

setname

(string $name=''

)//控制器分批次寫入資料到檔案防止記憶體不夠

public

function

writedata

(array

$data

,array

$field

, int $is_head

, string $txtfile

)foreach

($data

as$key

=>

$value

)// 寫檔案

$handle

=fopen

($txtfile

,'a');

fwrite

($handle

,$context);

fclose

($handle);

}//壓縮檔案

public

function

tozip

(string $txtfile

)$fp

=fopen

($zipfile

,"r");

$file_size

=filesize

($zipfile);

$zipname

=explode

(directory_separator

,$zipfile);

header()

;header

("accept-ranges: bytes");

header

("accept-length:"

.$file_size);

header

("content-disposition: attachment; filename="

.$zipname

[count

($zipname)-

1]);

$buffer

=1024

;$file_count=0

;while(!

feof

($fp)&&

$file_count

<

$file_size

)fclose

($fp);

if($file_count

>=

$file_size)}

/** *

* 呼叫示例

*/// public function testexport()

// fileexport::init()->setname('使用者資料-'.date('y-m-d',time()))->tozip($txtfile);

// }

}

PHP ThinkPhp5 實現token登陸

1 首先在資料庫的 users 表中新增兩個字段 1 token 2 time out token 用於儲存使用者的 token time out 用於設定使用者 token 的過期時間 首先建立函式 checktoekn token 函式用於檢驗 token 是否存在,並且更新 token pub...

PHP thinkPHP 效能提公升之旅

公司有乙個dsp平台 廣告平台 rtb模式 方會請求我們的api,我們需要返回參與競價的廣告資料。方對api的要求只有乙個 必須在100ms做出回應!一陣折騰,上線 測試 聯調,超時率 95 優化之旅 1.將url從網域名稱訪問改為ip訪問 節省大概10ms 2.將mysql連線位址 localho...

PHP,thinkphp學習筆記之一 基

第一,什麼是php?php就是免費的,開源的,mvc開發模式,物件導向的,輕量級的語言 m model 模型 工作 負責資料操作 v viel 檢視模板,工作 就是負責前台 c controller 模組功能 控制器 工作 負責描述功能 第二 環境搭建 安裝 wampserver 整合環境 裝好後在...