Lyleyboy Posted January 13, 2010 Share Posted January 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188335-weird-php-error-message/ Share on other sites More sharing options...
ToonMariner Posted January 13, 2010 Share Posted January 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188335-weird-php-error-message/#findComment-994247 Share on other sites More sharing options...
Lyleyboy Posted January 13, 2010 Author Share Posted January 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188335-weird-php-error-message/#findComment-994392 Share on other sites More sharing options...
ToonMariner Posted January 14, 2010 Share Posted January 14, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/188335-weird-php-error-message/#findComment-994634 Share on other sites More sharing options...
Lyleyboy Posted January 14, 2010 Author Share Posted January 14, 2010 Thanks for that. I have tried that code but got the same error. As I say the weird thing is that it's working fine but still giving me the error message. Quote Link to comment https://forums.phpfreaks.com/topic/188335-weird-php-error-message/#findComment-994742 Share on other sites More sharing options...
PFMaBiSmAd Posted January 14, 2010 Share Posted January 14, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/188335-weird-php-error-message/#findComment-994825 Share on other sites More sharing options...
ToonMariner Posted January 14, 2010 Share Posted January 14, 2010 I suspect that you are constantly increasing the email_message string rather than resetting it for each email to be sent... Quote Link to comment https://forums.phpfreaks.com/topic/188335-weird-php-error-message/#findComment-994974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.