Php 即使在再次执行该进程后,内存使用也会增加
我有一个symfony1.4任务,它使用splFileObject打开一个超过200000行的csv文件 这是负责打开文件的代码:Php 即使在再次执行该进程后,内存使用也会增加,php,memory,symfony-1.4,Php,Memory,Symfony 1.4,我有一个symfony1.4任务,它使用splFileObject打开一个超过200000行的csv文件 这是负责打开文件的代码: //open the CSV file for read $this->file = new SplFileObject($this->filePath, 'r'); $this->file->setFlags(SplFileObject::READ_CSV); $this->file->set
//open the CSV file for read
$this->file = new SplFileObject($this->filePath, 'r');
$this->file->setFlags(SplFileObject::READ_CSV);
$this->file->setCsvControl($this->delimiter);
$this->file->seek($this->options['limit']);
$this->limit = $this->options['limit'];
/* * read the file* */
$i = $this->limit + 1;
foreach ($this->file as $row)
{
if ($this->file->valid())
{
//initialize invoices and clients object
$this->initInvoicesArray($row);
$this->prepareInvoice();
//clear the row
unset($row);
$this->key = $this->file->key();
//add msisdn to msisdn array, and client to clients array
self::$InvoicesArray[$this->msisdn] = $this->client;
//get valid users from table, and save to payment_notifications
$this->prepareAndSaveValidClients();
if ($i % $this->options['count'] === 0)
{
//launch process again with new $key
$this->logSection('Payment Notification', $i. 'Lines Processed, Memory Usage : ' . memory_get_usage());
$this->log($this->fileSys->execute("./symfony mediapi:send-payment-notifications --application=" . $this->options['application']
. " --env=" . $this->options['env'] .
" --limit=" . $i .
' --count=' . $this->options['count']));
}
}
$i++;
}
如您所见,一旦限制达到1000行,我就会执行该过程。“限制”选项用于确定当前进程必须从文件中的哪一行开始
$this->prepareAndSaveValidClient()
是一个使用select验证数据、准备对象并将数据保存到数据库的函数。。。这是PrepareAndSaveValidClient():
问题在于,内存的使用会通过不同的进程增加:
Process 1 : 1000 Lines Processed, Memory Usage : 40947336
Process 2 : 2000Lines Processed, Memory Usage : 69401208
Process 3 : 3000Lines Processed, Memory Usage : 98444272
Process 4: 4000Lines Processed, Memory Usage : 126308156
...
如何启动新进程并释放以前的进程内存使用量
谢谢你“并释放上一个进程的内存使用”-你认为它为什么没有被释放?谢谢你的问题,我使用了内存使用函数来确定当前进程的内存使用。。。正如你所看到的,它正在增加。任务以一个内存被检查的致命错误结束,只有10%的行没有执行。“当前进程的内存使用情况”我只能假设这可能与原则有关,也可能与循环引用有关。您必须更深入地调试代码,以找出对象未被销毁的位置和原因。@KarolyHorvath我指的不是当前进程的“部分”,而是当前进程的“部分”,以及以前的进程。。。似乎内存没有被释放。
Process 1 : 1000 Lines Processed, Memory Usage : 40947336
Process 2 : 2000Lines Processed, Memory Usage : 69401208
Process 3 : 3000Lines Processed, Memory Usage : 98444272
Process 4: 4000Lines Processed, Memory Usage : 126308156
...