Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes)

Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes)

Scheduled Pinned Locked Moved Database
helpphpperformancequestion
8 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mahtabpi
    wrote on last edited by
    #1

    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 ?

    L J J 3 Replies Last reply
    0
    • M Mahtabpi

      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 ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • M Mahtabpi

        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 ?

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        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.)

        M 1 Reply Last reply
        0
        • L Lost User

          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.

          M Offline
          M Offline
          Mahtabpi
          wrote on last edited by
          #4

          Ok Thanks , Now What's the true format of this code ?

          L 1 Reply Last reply
          0
          • J jschell

            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.)

            M Offline
            M Offline
            Mahtabpi
            wrote on last edited by
            #5

            Ok Thanks , Now What's the true format of this code ?

            J 1 Reply Last reply
            0
            • M Mahtabpi

              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 ?

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              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 term

              SELECT * FROM tablename WHERE

              or get the data in chuncks (page wise) using the LIMIT clause: PHP Limit Data Selections From MySQL[^].

              1 Reply Last reply
              0
              • M Mahtabpi

                Ok Thanks , Now What's the true format of this code ?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                The true format is to understand how computers handle and store information, and not to assume that memory is infinite.

                1 Reply Last reply
                0
                • M Mahtabpi

                  Ok Thanks , Now What's the true format of this code ?

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups