Reputation: 295
the function is like following:
public function getFile($fileFullPath){
echo round(memory_get_usage()/1024/1024,2).'MB'.PHP_EOL;
$PHPReader = PHPExcel_IOFactory::createReaderForFile($fileFullPath);
if(! $PHPReader){
return false;
}
$PHPExcel = $PHPReader->load($fileFullPath);
$currentSheet = $PHPExcel->getActiveSheet();
return $currentSheet
}
the function is called by a while loop . and when running the program, the memory is increase constantly . the output info like this :
➜ crontab git:(f_*****) ✗ php worker.php program_name.php
1.64MB
8MB
10.56MB
12.99MB
15.68MB
18.11MB
20.54MB
23.47MB
25.91MB
28.34MB
30.77MB
is anyone familiar with the PHPExcel Library, and tell me how can I init the cache between every while loop finaly stoping the increase of the memory using.
Upvotes: 1
Views: 172
Reputation: 295
thanks for yours concern. I have found out the solution. In every loop of the while . I delete the cache of the sheet like :
while(true){
$currentSheet = $this->getFile($fullPath);
... //do anything with $currentSheet;
$currentSheet->disconnectWorksheets(); // drop the cache;
}
Through the disconnectWorksheets of the PHPlibrary. It drop the cache of cells. so the memory stop increasing.
Upvotes: 0
Reputation: 562
Tried this?
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
Upvotes: 2