-1

I have developed a web application that generates some files using phpSpreadSheet and I have this application in an Ubuntu Server. phpSpreadSheet uses memory of the server to generate this files, but when I generate files like 10 times I get this error:

Fatal error: Out of memory (allocated 72355840) (tried to allocate 20480 bytes) in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Collection/Cells.php on line 159

I´ve found out that it´s because after files are generated memory of server is still full (image example). Is there any way to clean this memory with PHP?

EDIT: I have found out that if I restart Apache2 memory is cleaned, is there any way on Ubuntu to restart server when memory is full?

nikeyah511
  • 11
  • 4
  • When looking at memory usage, use 'free -m' command. In linux, having very low 'free' memory is normal due to kernel caching. Your application appears to be terribly inefficient with memory usage. Fixing your application or finding another package that handles file generation is probably something worth doing. – Dimi Apr 07 '20 at 13:12
  • @Dimi The problem is that when it finishes to execute the method to generate files that memory is not been cleaned. So when I execute it a number of times the memory gets full. Is there any way to clean it after every execution? – nikeyah511 Apr 07 '20 at 13:16
  • you can start by trying to optimize your PHP so it uses less memory. You can also learn about Garbage Collection: https://www.php.net/manual/en/features.gc.performance-considerations.php – Ron Apr 07 '20 at 14:06
  • I would take a close look at your code, and sharing it here might help, as it might be contributing to your problem. You should not normally be seeing an issue like that when creating multiple files and you should not have to add things to "fix" the problem. – Dave Apr 08 '20 at 11:22

1 Answers1

0

I finally resolve it adding Swap to my Ubuntu server. Here you can check how to add it

nikeyah511
  • 11
  • 4