Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes)
-
Hi I wrote this code in notepad ++ :
And run it with wamp localhost . Then I got this error in my browser : Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes) in D:\...\page1.php on line 10 What's problem ? Can anybody says ?
-
Hi I wrote this code in notepad ++ :
And run it with wamp localhost . Then I got this error in my browser : Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes) in D:\...\page1.php on line 10 What's problem ? Can anybody says ?
-
Hi I wrote this code in notepad ++ :
And run it with wamp localhost . Then I got this error in my browser : Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes) in D:\...\page1.php on line 10 What's problem ? Can anybody says ?
Adding to the above. Never attempt to return all records from a table(s) where that table can have a 'large' size where large can range from about 10,000 and on up. Never do this when the result is for a UI. Just do not allow it. Reason is that no user is going to page through hundreds of pages (multiple items per page) randomly. Rather such a user always knows what they are looking for so require that the user provide more information to narrow the search. This can be designed specifically such that the api (your method) requires paging (page number and page size) and then the method only returns that page. Additionally the framework or php is providing an implementation of an array which grows to meet the maximum size of data. That is optimized to grow at a rate which is probably doubling every time the previous limit is reached. And you are attempting to put a very large number of records in that array. So at that limit it attempts to double the size of the existing array and fails because there is no more memory in the application. Fix the design rather than attempting to optimize the size yourself (don't return everything.)
-
The problem is that you are trying to create some variable that is too big for the amount of available memory. Most likely you are extracting too many records from the database.
-
Adding to the above. Never attempt to return all records from a table(s) where that table can have a 'large' size where large can range from about 10,000 and on up. Never do this when the result is for a UI. Just do not allow it. Reason is that no user is going to page through hundreds of pages (multiple items per page) randomly. Rather such a user always knows what they are looking for so require that the user provide more information to narrow the search. This can be designed specifically such that the api (your method) requires paging (page number and page size) and then the method only returns that page. Additionally the framework or php is providing an implementation of an array which grows to meet the maximum size of data. That is optimized to grow at a rate which is probably doubling every time the previous limit is reached. And you are attempting to put a very large number of records in that array. So at that limit it attempts to double the size of the existing array and fails because there is no more memory in the application. Fix the design rather than attempting to optimize the size yourself (don't return everything.)
-
Hi I wrote this code in notepad ++ :
And run it with wamp localhost . Then I got this error in my browser : Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes) in D:\...\page1.php on line 10 What's problem ? Can anybody says ?
As already explained by others the error tells you that you ran out of memory because you have requested to return all data from a huge database. Your program stops execution when
$myArray
is full while using already 408 MB of memory. Then the allocation of additional 805 MB failed (the already allocated 408 MB would be freed but that would occur after the content has been copied to the new memory). You have to limit the number of returned data by using a search termSELECT * FROM tablename WHERE
or get the data in chuncks (page wise) using the
LIMIT
clause: PHP Limit Data Selections From MySQL[^]. -
Depends on usage... But one implementation, as I already suggested would be to pass in a 'page' and 'page size'. Then your method finds the 'page' and returns no more than 'page size' items. Then your 'Array' would never be any bigger than 'page size'. Could be less because there could be less than that.