Last active
July 27, 2022 16:05
-
-
Save cccaballero/e8e501671c387e035f24ab76774b6e7d to your computer and use it in GitHub Desktop.
Yii2 console app memory leak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace console\controllers; | |
use yii\console\Controller; | |
class TestController extends Controller | |
{ | |
public function actionTest(){ | |
$db = \Yii::$app->db; | |
$chunkSize = 1000; | |
$chunkCount = 0; | |
$columns = [ | |
'id', | |
'a', | |
'b', | |
'c', | |
'd', | |
'e', | |
'f', | |
'g', | |
'h', | |
'i', | |
'j', | |
'k', | |
'l', | |
'm', | |
'n', | |
'o', | |
'p', | |
'q', | |
'r', | |
's', | |
't', | |
'u', | |
'v', | |
'w', | |
'x', | |
'y', | |
'z', | |
'aa', | |
'ab', | |
'ac', | |
'ad', | |
'ah', | |
'ai', | |
'aj', | |
'ak', | |
'al', | |
'am', | |
'an', | |
'ao', | |
'ap', | |
'aq', | |
'ar', | |
'as', | |
'at', | |
'au', | |
'av', | |
'aw', | |
'ax', | |
'ay', | |
'az', | |
'ba', | |
'bb', | |
'bc', | |
'bd', | |
'be', | |
'bf', | |
'bg', | |
'bh', | |
'bi', | |
'bj', | |
'bk', | |
'bl', | |
'bm', | |
'bn', | |
'bo', | |
'bp', | |
'bq', | |
'br', | |
'bs', | |
]; | |
$value = [ | |
null, | |
'a', | |
'b', | |
'c', | |
'd', | |
'e', | |
'f', | |
'g', | |
'h', | |
'i', | |
'j', | |
'k', | |
'l', | |
'm', | |
'n', | |
'o', | |
'p', | |
'q', | |
'r', | |
's', | |
't', | |
'u', | |
'v', | |
'w', | |
'x', | |
'y', | |
'z', | |
'aa', | |
'ab', | |
'ac', | |
'ad', | |
'ah', | |
'ai', | |
'aj', | |
'ak', | |
'al', | |
'am', | |
'an', | |
'ao', | |
'ap', | |
'aq', | |
'ar', | |
'as', | |
'at', | |
'au', | |
'av', | |
'aw', | |
'ax', | |
'ay', | |
'az', | |
'ba', | |
'bb', | |
'bc', | |
'bd', | |
'be', | |
'bf', | |
'bg', | |
'bh', | |
'bi', | |
'bj', | |
'bk', | |
'bl', | |
'bm', | |
'bn', | |
'bo', | |
'bp', | |
'bq', | |
'br', | |
'bs', | |
]; | |
$values = []; | |
while (true) { | |
var_dump(memory_get_usage()); | |
$values[] = $value; | |
if ($chunkCount >= $chunkSize) { | |
$db->createCommand()->batchInsert('test', $columns, $values)->execute(); | |
$chunkCount = 0; | |
$values = []; | |
} | |
$chunkCount++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment