Yii2 Allowed memory size exhausted

萝らか妹 提交于 2020-06-23 07:57:28

问题


I'm uploading file to my Yii2 project. The file it self is ~100kB, contains ~45 000 short lines that are processed by controller and added line-by-line to the database.

How could I trace exactly when the error occurs or what it is that's eating up the memory? The limit set in php.ini is currently 512MB. And what does LogTarget have to do with it anyway? Afaik i'm not logging anything during this upload and update process.

Can this thing happen, when something else is using server's memory? A'la other background scripts?


回答1:


The error isn't in this line. I had the same error when i had imported data from an excel file and logged some "models" data with print_r or var_dump where the whole "model" is added to the log (including relations traversing etc.)

You can fix this by limiting the depth of the dump by using the Vardumper instead of print_r or var_dump and setting a depth (e.g. 3)

yii\helpers\VarDumper::dumpAsString($var, $depth, $highlight)

Then only the code is returned to this depth and the log would getting smaller.

Also if you have many inserts / updates to your database the log will get pretty long.

The problem btw comes from the debug toolbar. You wouldn't get the error if the debug module is disabled.

but other then increasing the memory there isn't real solution




回答2:


I already had experience of such situations. You can act in two ways

1) - raising the memory_limit parameter in php.ini

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
; memory_limit = 128M
memory_limit = 256M

2) - by splitting the file you're iterating into smaller parts and manage them with separate scripts (or separate post)



来源:https://stackoverflow.com/questions/32944442/yii2-allowed-memory-size-exhausted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!