MasterACE14 Posted May 15, 2010 Share Posted May 15, 2010 Hello, I'm receiving the following error... Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /home/ace/public_html/site/sys.php on line 342 the error is coming from the following function... function getWeaponArray($Weapons,$WeaponCount ){ $weaponA = false; $weaponAW=explode(";",$Weapons); $weaponAWC=explode(";",$WeaponCount); $k=0; for ($i=0;$i<count($weaponAW);$i++){ for ($j=0; $j<$weaponAWC[$i] ;$j++){ $weaponA[$k]=$weaponAW[$i]; // Line 342 $k++; } } return $weaponA; } Is there a better way to write this function? or have I made a simple mistake? appreciate the help. Thanks, Ace Quote Link to comment https://forums.phpfreaks.com/topic/201854-allowed-memory-size-of-985353-bytes-exhausted/ Share on other sites More sharing options...
MasterACE14 Posted May 15, 2010 Author Share Posted May 15, 2010 made a minor performance adjustment, still same error coming up though: function getWeaponArray($Weapons,$WeaponCount ){ $weaponA = false; $weaponAW=explode(";",$Weapons); $weaponAWC=explode(";",$WeaponCount); $k=0; $weaponAWcount = count($weaponAW); // count $weaponAW before the 'for' loop for ($i=0;$i<$weaponAWcount;$i++){ for ($j=0; $j<$weaponAWC[$i] ;$j++){ $weaponA[$k]=$weaponAW[$i]; // Line 342 $k++; } } return $weaponA; } Quote Link to comment https://forums.phpfreaks.com/topic/201854-allowed-memory-size-of-985353-bytes-exhausted/#findComment-1058699 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2010 Share Posted May 15, 2010 Unless $Weapons, $WeaponCount, $weaponAW, and $weaponAWC are large and using ~134 million bytes of memory, the problem is your overall script is using all available memory and when you attempt to create the $weaponA array, you cannot allocate enough memory. What are the sizes of $Weapons and $WeaponCount? If they are fairly small, the problem is elsewhere and you would need to find where your script is using most of the memory and optimize it. Quote Link to comment https://forums.phpfreaks.com/topic/201854-allowed-memory-size-of-985353-bytes-exhausted/#findComment-1058708 Share on other sites More sharing options...
MasterACE14 Posted May 15, 2010 Author Share Posted May 15, 2010 they're both 35, I guess the problem lies somewhere else then. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/201854-allowed-memory-size-of-985353-bytes-exhausted/#findComment-1058709 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2010 Share Posted May 15, 2010 Are you reading whole (large) files into memory or returning large queries from databases and then making copies of the returned data in arrays or using a php framework or any other things that use large amounts of memory or are you using large amounts of memory but are not freeing them up once you are done with them? It would take seeing your code and knowing the size of the data being used in order to help. Quote Link to comment https://forums.phpfreaks.com/topic/201854-allowed-memory-size-of-985353-bytes-exhausted/#findComment-1058716 Share on other sites More sharing options...
satya61229 Posted May 15, 2010 Share Posted May 15, 2010 See if you are reading large file in memory then this is going to happen. In this case just increase the memory size for php for that script. If it is just a script that is causing the problem then check the script. Search for PHP memory_limit . ini_set('memory_limit', 'size in bytes'); http://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-bytes Quote Link to comment https://forums.phpfreaks.com/topic/201854-allowed-memory-size-of-985353-bytes-exhausted/#findComment-1058754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.