ashly Posted February 27, 2007 Share Posted February 27, 2007 Can anyone explain how to free the memory in PHP script after a block of code is executed? I am using PHP5 on apache server Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/ Share on other sites More sharing options...
Jenk Posted February 27, 2007 Share Posted February 27, 2007 the Zend (PHP) engine does it for you. Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/#findComment-195100 Share on other sites More sharing options...
play_ Posted February 27, 2007 Share Posted February 27, 2007 Pretty sure GC does it automatically for you. (it even closes open mysql connections) Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/#findComment-195103 Share on other sites More sharing options...
btherl Posted February 27, 2007 Share Posted February 27, 2007 If you finish a function, memory for variable accessible ONLY in that function will be reused automatically. Variables accessible outside the function will not be freed automatically. If variables are still in scope and you want to reuse their memory, you should use unset($var). Edit: And if the script finishes, then all memory used by it will be freed (in theory, there's some bugs related to that in php4, I think they are fixed in php5). Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/#findComment-195104 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 what about the memory_get_usage() function? is it the real memory space used by the script? bcse i got a value -51269756 when i checked in my script.. what is the mening of -ve value? and it makes problem for me to execute the script completely. i have increased the ini setting value for memory_limit and set it to 500 MB.. Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/#findComment-195112 Share on other sites More sharing options...
btherl Posted February 27, 2007 Share Posted February 27, 2007 I don't trust php 5's memory_get_usage(). It doesn't always give sensible values. You might want to print out the memory usage at various stages throughout your program and track it, and see what's going on. Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/#findComment-195131 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 anyway, my problem is not that function.. i thought it was because of memory limit.. my script doesn't complete the execution and it results in "Network Error (tcp_error) ". I have to make around 6 pdf's in a single script. but there is a large amount of data.. around 1500 records in each pdf. but i cannot even finish one pdf. can anyone help me to sort out the problem? Thanks Ashly Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/#findComment-195183 Share on other sites More sharing options...
Jenk Posted February 27, 2007 Share Posted February 27, 2007 set_time_limit(0); and wait potentially a long time. Link to comment https://forums.phpfreaks.com/topic/40326-how-to-release-memory-in-php/#findComment-195223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.