Tom
Tom

Reputation: 1223

API with hundrets of forms - out of memory

In my Symfony 2.6 project I have API for mobile app that gives a possibility to add and object with lots of data.

Main form consists of collection of other forms. Each of child forms have the same things, 4 in total. So the structure looks like this:

Master form has Child1 forsm which has Child2 forms which has Child3 forms.

The object has for instance 2 000 entities for Child3, 8 Child2 entities, 3 Child1 entities and one Master entity.

Many times I get this error while saving data:

AH01071: Got error 'PHP message: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 88 bytes) in /vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/OptionsResolver.php on line 755\n'

I have just add types to all forms elements, like:

$buider->add('startLangutude', 'text')

Also I have turned off SQLLogger. Is there any other neat solution that could help here? Do you have any experience in it and could share?

Upvotes: 1

Views: 140

Answers (1)

Valentas
Valentas

Reputation: 2175

I would suggest You to drop Form approach and use simple json_decode to get array (it's cheaper resource wise compared to Object), then create a bunch of ArrayToEntityTransformer using StrategyPattern. In each strategy You can validate given array before object creation process. If object is valid, use doctrine batch processing recommendations to save memory by clearing EntityManager after each batch.

Good luck.

Upvotes: 3

Related Questions