private function getWeaponsInfo() { $parameters = array('iDisplayStart' => 0, 'iDisplayLenght' => 50, 'type' => 1); $response = file_get_contents($this->url . '?' . http_build_query($parameters)); $response = json_decode($response, true); $data = $response['aaData']; $formattedData = array(); //Formatting Data foreach ($data as $value) { $index = $value[0]['name'] . $value[0]['requiredLevel']; $formattedData[$index] = array('name' => $value[0]['name'], 'description' => $value[0]['description'], 'level' => $value[0]['requiredLevel']); } $i = 0; foreach ($formattedData as $value) { $i++; $item = new Item(); $item->setName($value['name']); $item->setDescription($value['description']); $item->setLevel($value['level']); $item->setType('weapon'); $this->em->persist($item); if ($i % 20 === 0) { $this->em->flush(); $this->em->clear(); } } $this->em->flush(); $this->em->clear(); }