Jump to content

Weird php error message


Lyleyboy

Recommended Posts

Hi all,

 

I seem to have a weird issue. I have a form that updates a table, then exports the table contant to csv and emails the csv.

 

When I come to save the changes in the form I get the following error.

 

Fatal error: Allowed memory size of 15728640 bytes exhausted (tried to allocate 6555470 bytes) in PATH TO FILE.php on line 933

 

I have added

ini_set("memory_limit","15M");

to make sure that there is enough memory but still the same.

Incidentally I initially added 12M and the figure in the error read 12728640.

 

The thing is that it all works perfectly. I'm no pro and I'm confused. Below is the section of the code.

 

929    $email_message .= "This is a multi-part message in MIME format.\n\n" .
930	  "--{$mime_boundary}\n" .
931	  "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
932	  "Content-Transfer-Encoding: 7bit\n\n" .
933	  $email_message . "\n\n";

 

Just as a point the file when it arrives is only 19KB in size.

 

Any help would be great thanks.

Link to comment
Share on other sites

clearly using up lots of memory...

 

check your script to see if there are any cyclic calls (ie anything that will act as recursion), if you are opening files make sure you clear the cache once you have closed them (suspect this is the culprit).

 

let us know how you get on.

Link to comment
Share on other sites

Thanks for the response. As I feared I have no clue what you mean.

 

I am opening a file which is the CSV but as far as I am aware I'm closing it.

 

The code where the file is being used. I reckon you could be right as this has been working for ages and not having the problem. I have recently added a few bits to the table and therefore the file.

 

		    
//Now we export to CSV
	    
	    
$file = "../../logs/backups/users.csv";
	    
$fh = fopen($file, 'w') or die("can't open file");
	    
	    
	    
$data = "user_id,username,password,surname,first_name,email,mobile,dob,address1,address2,address3,post_code,parents_title,parents_initial,parents_name,parents_surname,nat_h_no,doctors_name,doctors_address,tetanus_data,medical,paying,allowed,allowed_notes,night,bronze,silver,gold,moderator,admin,s_admin,webmail,over18,date_joined,leaving_date,home_phone,parents_mobile,y_leader_location,dofe_id,notes,crb_id,crb_expiry";
	    
fwrite($fh, $data);
	      
//Now write all lines to the csv
	      
$cr = "\n";
	      
$query = "SELECT * FROM users"; 
	      
$result = mysql_query($query) or die(mysql_error());
	      
while($row = mysql_fetch_array($result)){
	        
  $data =  $cr;
	        
  fwrite($fh, $data);
	        
  $data =  $row['user_id'] . "," . $row['username'] . "," . $row['password'] . "," . $row['surname'] . "," . $row['first_name'] . "," . $row['email'] . "," . $row['mobile'] . "," . $row['dob'] . "," . $row['address1'] . "," . $row['address2'] . "," . $row['address3'] . "," . $row['post_code'] . "," . $row['parents_title'] . "," . $row['parents_initial'] . "," . $row['parents_name'] . "," . $row['parents_surname'] . "," . $row['nat_h_no'] . "," . $row['doctors_name'] . "," . $row['doctors_address'] . "," . $row['tetanus_data'] . "," . $row['meidcal'] . "," . $row['paying'] . "," . $row['allowed'] . "," . $row['allowed_notes'] . "," . $row['night'] . "," . $row['bronze'] . "," . $row['silver'] . "," . $row['gold'] . "," . $row['moder'] . "," . $row['admin'] . "," . $row['s_admin'] . "," . $row['webmail'] . "," . $row['over18'] . "," . $row['date_joined'] . "," . $row['leaving_date'] . "," . $row['home_phone'] . "," . $row['parents_mobile'] . "," . $row['y_leader_location'] . "," . $row['dofe_id'] . "," . $row['notes'] . "," . $row['crb_id'] . "," . $row['crb_expiry'];
	        
  fwrite($fh, $data);
	      
}
	    
fclose($fh);

 

If you can see an issue I'd be very grateful of some pointers.

 

Thanks again.

Link to comment
Share on other sites

Try this...

 

<?php
//Now we export to CSV   
	    
$file = "../../logs/backups/users.csv";
	    
$fh = fopen($file, 'w') or die("can't open file");

$data = "user_id,username,password,surname,first_name,email,mobile,dob,address1,address2,address3,post_code,parents_title,parents_initial,parents_name,parents_surname,nat_h_no,doctors_name,doctors_address,tetanus_data,medical,paying,allowed,allowed_notes,night,bronze,silver,gold,moderator,admin,s_admin,webmail,over18,date_joined,leaving_date,home_phone,parents_mobile,y_leader_location,dofe_id,notes,crb_id,crb_expiry" . PHP_EOL;
	    
fwrite($fh, $data);
	      
//Now write all lines to the csv
	      
$query = "SELECT * FROM users"; 
	      
$result = mysql_query($query) or die(mysql_error());
	      
while($row = mysql_fetch_assoc($result)){
	        
  $data =  implode(',',$row) . PHP_EOL;
	        
  fwrite($fh, $data);
	      
}
	    
fclose($fh);
?>

Link to comment
Share on other sites

What does the code in the first post in this thread have to do with this problem? It is not present in any of the other code you have posted. Given the line number mentioned in the error message, that is not all of the code that is relevant to this problem and the problem might in fact not have anything to do with the code posted in reply #2.

 

About the only affect the code in reply #2 (and the minor change in the code in reply #3 would have no appreciable impact on this problem) would have on total memory usage is if the result resource is referenced later in the code so that the built-in resource garbage collector is not freeing up the memory used by that code. You can add a mysql_free_result after that code to see if it helps.

 

You are having a memory usage problem on your page. Either your code just naturally requires that amount of memory or your code is not efficiently using memory or freeing up memory after it is no longer needed. It would take seeing the code on your page to determine which of these things are the cause of the problem. Through I'm not sure anyone wants to see 900+ lines of code that is already using 15mb of memory and just attempted to allocate 6mb more...

Link to comment
Share on other sites

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.