Jump to content

"Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 36 bytes)" what does it mean?


Go to solution Solved by jazzman1,

Recommended Posts

Hi everyone

 

I get error message from website - "Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 36 bytes) in" what does it mean? Do I have increase of memory in php.ini?  Please let me know

 

Thank you,

Gary

Edited by sigmahokies

It means it tried to allocate 36 more bytes of memory but this exceeds the 64MB memory limit. You can increase the memory but if this happens again then this signifies there is a problem with your script consuming to much memory.

 

64MB should be more than enough for your needs.

Edited by Ch0cu3r

Exceeded the max memory limit.

 

Can try to increase it or lower the memory usage for your script.

 

php.ini

memory_limit = 128M;

 

htaccess

php_value memory_limit 128M;

 

top of php script

ini_set('memory_limit','128M');

Edited by QuickOldCar

Cronix, I don't know why it ran out of memory, but strange is previous page is work but next page is not work, but yet program is nearly same as previous page. in few weeks ago, i put thread to hope someone will help me to do table vertical cell data that from GET and POST, several people answer in comment, so I tried to fix by learn from those comment, then page went into error showing those quote about memory is not allowed. Previous page, it works fine, then next page, message error just show up.

Wild guess but you have a loop that is doing something for you but you have allowed it to continue on too long without ending and that's is causing the excess memory usage. Check your foreach or while loops to be sure that they will reach an 'end point' at some time and not keep on forever.

but yet program is nearly same as previous page

 

 

in programming, a simple typo in a variable name, can cause your program logic to loop forever, because the code is no longer testing the correct variable.

 

if you cannot find the problem in your code that is causing this, you will need to post the code that reproduces the problem.

 

 

i put thread to hope someone will help me to do table vertical cell data that from GET and POST, several people answer in comment, so I tried to fix by learn from those comment, then page went into error showing those quote about memory is not allowed

 

You should post the code that you altered in your above comment then if it was working previous to your modifications

You want to see my code? there is still see post my code in other thread, called "what is "Fatal error: Unsupported operand types in" mean". Let me know if you can't find this thread, i will post my code in here...

Edited by sigmahokies

Typically, this happens in a database call if you don't code it right.

Let's say I have the following code

WRONG SAMPLE CODE:

<?php
$id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
$db = new mysqli('localhost', 'root', 'root', 'root');
$mysqli = $db->prepare("SELECT name FROM test_table WHERE id = ?");
$mysqli->bind_param("i", $id);
$mysqli->execute();
$mysqli->bind_result($name);
while($mysqli->fetch()) {
	print_r($name);
}
?>

It actually will throw you that error because your code looks through your database with the information you are giving it via $_POST, $_GET, .etc. However, since the data it is looking for does not really truly exist in the database, there is no error handling for it so it will just continuously look for the data over and over and therefore the script will actually not stop. That is why you are getting the exhaust error. You have to put your code inside an if statement to make sure that it truly does have that data in your database.

Here is the right code.

 

RIGHT SAMPLE CODE:

<?php
$id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
$db = new mysqli('localhost', 'root', 'root', 'root');
$mysqli = $db->prepare("SELECT name FROM test_table WHERE id = ?");
$mysqli->bind_param("i", $id);
$mysqli->execute();
$mysqli->store_result();
if($mysqli->num_rows) {
	$mysqli->bind_result($name);
	while($mysqli->fetch()) {
		print_r($name);
	}
} else {
	print("Requested data does not exist.");
}
?>

jennifer lawerence

 

I am not using database to make display, I am using GET and POST to display the data. in previous page,I am using database to display because it shows ALL names on display, in next page, I use GET and POST to collect data name that who "show up" for different reasons. For example, there will be meeting in the club, then president request someone to check any member who come in for meeting, then checklist is complete, then click on submit to next page website, then officer can see list of member who showed up at meeting this time, because not all members will show up at meeting.

 

That is what I am trying to create this website. I am still learning PHP.

jennifer lawerence

 

I am not using database to make display, I am using GET and POST to display the data. in previous page,I am using database to display because it shows ALL names on display, in next page, I use GET and POST to collect data name that who "show up" for different reasons. For example, there will be meeting in the club, then president request someone to check any member who come in for meeting, then checklist is complete, then click on submit to next page website, then officer can see list of member who showed up at meeting this time, because not all members will show up at meeting.

 

That is what I am trying to create this website. I am still learning PHP.

 

It is best to show us the code. I'm speculating that you are still pulling data from a database. Otherwise, where is the data being pulled from? A text file? An array of lists in your code?

 

There has to be at least some sort of data type for you to pull from.

Jennifer,

 

All right, there will be two pages code

 

First page code:

<!doctype html>
<html>
<head>
<title>Test array with columns</title>
</head>
<body>
<form action="testarray3.php" method="GET">
<fieldset>
<?php
$column = 5;
 
$Garydb = mysqli_connect(xxxx','xxxx',xxxx') or die("Could not connect to database.");
mysqli_select_db($Garydb, 'xxxx');
$sql = "SELECT CONCAT(FirstName,' ',LastName) AS Name FROM Members ORDER BY LastName ASC";
$result = mysqli_query($Garydb, $sql);
$num_rows = mysqli_num_rows($result);
$rows = ceil($num_rows / $column);
while ($row = mysqli_fetch_array($result)) {
$data[] = $row['Name'];
}
echo "<table border='7'>\n";
for($i = 0; $i < $rows; $i++) {
echo "<tr>\n";
for($j = 0; $j < $column; $j++) {
if(isset($data[$i + ($j * $rows)])) {
echo "<td>".$data[$i + ($j * $rows)]."</td><td><input type='checkbox' name='member[]' value='".$data[$i + ($j * $rows)]."'></td>\n";
}
}
echo "</tr>\n";
}
echo "</table>\n";
?>
<input type="submit" value='Attendence'>
</fieldset>
</form>
</body>
</html>
 
Second Page (next page) Code:
 
<!doctype html>
<html>
<head>
<title>Test array attendence</title>
</head>
<body>
<table border="1">
<?php
$columns = 2;
$count = 0;
if(isset($_GET['member'])) {
$display = ceil($_GET['member']);
$rows = ceil($display/$columns);
while ($row = array($rows)) {
$data['Name'] = $row;
}
for($i = 0; $i < $rows; $i++) {
echo "<tr>";
for($j = 0; $j < $columns; $j++) {
if(isset($data[$i + ($j *  $row)])) {
echo "<td>".$data[$i + ($j *  $row)]."</td>";
$count = $count+1;
}
}
echo "</tr>";
}
}else{
echo "Fail to get data from previous";
}
?>
</table>
<table><tr><td><?php echo $count." are attending this meeting tonight." ?></td></tr></table>
</body>
</html>
 
Second pagesuppose collect data from first page. I'm trying to collect data that been checked on first page, then transfer data to second page. It works with ONE column. But I am trying to create the vertical data instead of row data, vertical data is working on first page, but not work on second page. I think "$data[$i + ($j * $row)]" is not necessary but I'm not sure. I am not professional in PHP yet, but I am learning PHP, I hope I will master PHP in one or two year later. PHP is not easy to understand...Thank you for patient with me.
 
Gary
Edited by sigmahokies
  • Solution

Try (second page):

<!doctype html>
<html>
    <head>
        <title>Test array attendence</title>
    </head>
    <body>
        <table border="1">
            <?php
            if (!empty($_GET['member'])) {
                
                $data = $_GET['member'];

                foreach (array_chunk($data, 2) as $row):
                    ?>
                    <tr>
                        <?php foreach ($row as $value): ?>
                            <td><?php echo htmlentities($value); ?></td>
                    <?php endforeach; ?>
                    </tr>
                <?php
                endforeach;
            }else {
                echo "Fail to get data from previous";
            }
            ?>
        </table>
        <table><tr><td><?php echo count($_GET['member']) . " are attending this meeting tonight." ?></td></tr></table>
    </body>
</html>

Hi Jazzman1

 

i followed exactly your code, seem it doesn't work...it gets "parse error, syntax error, unexpect 'endforeach' (T_ENDFOREACH) in" on 20 line. it is 18 line in your line in comment above of here.

Edited by sigmahokies

Cronix, Oops! I changed from ; to : on this line, my habit, heh.

 

Still get error message, it said "Parse error: syntax error, unexpected ':', expecting ',' or ';' in on line 18"

Edited by sigmahokies

Oh, I didn't realized there are two : on line 13 and 16, then I changed them to :

 

but still get error in array chunk, it said,

 

Warning: array_chunk() expects parameter 1 to be array, string given in on line 11

Warning: Invalid argument supplied for foreach() in  on line 11

1 are attending this meeting tonight.

 

11 line - foreach (array_chunk($data, 2) as $row): (13 line on jazzman1's comment above)

Edited by sigmahokies

 

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 36 bytes) in" what does it mean?

At first I thought it meant "We have 64Mb free, and we tried to allocate 36 bytes in that vast free space, but there was an error", which did not make sense to me.

 

But then I realized it means "We have been allocating memory right and left for the stuff you do in your script and all entire memory limit of 64Mb has been used up and is full.  Now when your rampant script tries to allocate 36 more bytes, we just can't take any more".  So increase your memory limit, or find a bug in your script that caused this high memory usage.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.