Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法用php清理Ubuntu服务器内存使用情况?_Php_Ubuntu_Memory_Ubuntu Server_Phpspreadsheet - Fatal编程技术网

有没有办法用php清理Ubuntu服务器内存使用情况?

有没有办法用php清理Ubuntu服务器内存使用情况?,php,ubuntu,memory,ubuntu-server,phpspreadsheet,Php,Ubuntu,Memory,Ubuntu Server,Phpspreadsheet,我已经开发了一个web应用程序,它使用phpSpreadSheet生成一些文件,我在Ubuntu服务器上有这个应用程序。phpSpreadSheet使用服务器内存生成此文件,但当我生成10次文件时,会出现以下错误: Fatal error: Out of memory (allocated 72355840) (tried to allocate 20480 bytes) in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpread

我已经开发了一个web应用程序,它使用phpSpreadSheet生成一些文件,我在Ubuntu服务器上有这个应用程序。phpSpreadSheet使用服务器内存生成此文件,但当我生成10次文件时,会出现以下错误:

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
我发现这是因为在生成文件之后,服务器的内存仍然是满的()。有没有办法用PHP清理这个内存


编辑:我发现,如果我重新启动Apache2,内存被清理,Ubuntu上有没有办法在内存满时重新启动服务器?

我终于解决了这个问题,将交换添加到我的Ubuntu服务器上。您可以检查如何添加它

在查看内存使用情况时,使用“free-m”命令。在linux中,由于内核缓存,具有非常低的“空闲”内存是正常的。您的应用程序在内存使用方面似乎非常低效。修复您的应用程序或找到另一个处理文件生成的包可能是值得做的事情。@Dimi问题是,当它完成执行生成文件的方法时,内存没有被清理。所以当我多次执行它时,内存就满了。有什么方法可以在每次执行后清理它吗?您可以从优化PHP开始,这样它就可以使用更少的内存。您还可以了解垃圾收集:我将仔细查看您的代码,在这里共享它可能会有所帮助,因为它可能会导致您的问题。通常,在创建多个文件时,您不应该看到这样的问题,您不应该添加一些东西来“修复”问题。