Home php PHP error Fatal Error. How to solve the problem?

PHP error Fatal Error. How to solve the problem?

Author

Date

Category

I took the cheapest hosting on unihost.com, filled online game – it works with 128MB of RAM. Then, by reference to the php file which is responsible for communicating with the MySQL database, got an error:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 43 bytes) in /var/www/user/data/www/site.ru/GameEngine/Database/db_MYSQL.php on line 2986 (today moved to hosting with 256MB, not helped ;-()

How to solve the problem? Should I move to a host with 384MB of RAM?

Here is a function in which the error occurs:

function mysql_fetch_all ($ result) {
    $ All = array ();
    if ($ result) {
      while ($ row = mysql_fetch_assoc ($ result)) {// line 2986
        $ All [] = $ row;
      }
      return $ all;
    }
  }

Answer 1, Authority 100%

As you can guess, the web application consumes all the memory available to a virtual server. Looking at your code given, it becomes clear that an error occurs when you try to move the result of a query to a database table in memory on the server. Obviously, the sample touches a huge number of entries (the total amount of information that 268435456/1024/1024 = = 256MB !!). There are several exits: limit the number of affected records request from the table (LIMIT, WHERE, etc) or start a server with lots of RAM to spare. Preferably, the first option, because in the future you will protect yourself from such a problem. Anyway, you need to watch out for things like that ..

Here, here, for example, only one line number scares:

& lt; b & gt; Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 43 bytes) in / var /www/user/data/www/site.ru/GameEngine/Database/db_MYSQL.php on line 2986 & lt; / b & gt;

Such gigantic scripts should be split into several files to at least to him then not to get confused ..


Answer 2, Authority 83%

Try adding to the beginning index.php (located at the root of the site) just such a place. Memory respectively indicate for their own purposes.

& lt;? Php ini_set ( "memory_limit", "512M"); ? & gt;

Or, to put in the root of the site the file .htaccess as follows:

php_value memory_limit 512M

If this does not help – contact the administrator host and ask to increase the amount of memory available for PHP

Try to use the mysql_fetch_row () instead of mysql_fetch_assoc ()


Answer 3

This error indicates that your script to run requires more memory than is allowed in PHP settings. Those. requested value exceeds the maximum amount of memory provided to the user account virtual hosting. At different hosting this value may vary.

If you’re experiencing this problem, you can do the following:

  1. Try by yourself to change this value, adding to the beginning index.php (located at the root of the site) the following lines:

    & lt;? Php ini_set ( "memory_limit", "512M"); ? & gt;
    

    or putting in the site root .htaccess file `as follows:

    php_value memory_limit 512M
    

    If the file already exists in the root of the site – just add the above line

  2. .

  3. If that does not help – contact the administrator host and ask to increase the amount of memory available for PHP

  4. .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions