[fix] for MySQL error 1153 -- 'max_allowed_packet' exceeded

Solutions for other phplisters - Questions go in the questions and problems forum

[fix] for MySQL error 1153 -- 'max_allowed_packet' exceeded

Postby thdyck » 3:18pm, Thu 21 Feb, 2008

Hi all,

When processing bounces, I was getting a database error of:

Database error 1153 while doing query Got a packet bigger than 'max_allowed_packet' bytes


for every bounce in my queue and the bounce was being retrieved but not stored in the database (that is, lost).

Our list sends out attachments with e-mails and so the bounces are 3-5 MB in size.

We are using MySQL 5.0.45 in a shared hosting environment. The documented solution is to change the max_allowed_packet server parameter to allow for larger inserts (the default limits SQL commands to 1048576 bytes). Because I do not control the server, I cannot change the server settings.

The MySQL documentation says that clients can also set this dynamically by issuing a "set session" command. e.g.

Code: Select all
  $increase = mysql_query("set session max_allowed_packet=10000000");
  if ($increased!=FALSE) echo "Can not increase packet size";


However, I did this right before the insert into the bounce table that causes the problem and it didn't prevent the error. I also read the value back to ensure it had been changed and the session setting value had indeed been changed, but the solution still did not work. Some others have posted messages on MySQL forums saying the same. Changing the server parameters in other ways does appear to work, if you can do that.

So, as another approach, I edited the code inserting bounced messages into the database to limit the message body to 1000000 bytes in size, which avoids the issue entirely. They still process correctly as all the header information is still included.

In processbounces.php:

Code: Select all
  ...

  Sql_Query(sprintf('insert into %s (date,header,data)
    values("%s","%s","%s")',
    $tables["bounce"],
    date("Y-m-d H:i",@strtotime($headerinfo->date)),
    addslashes($header),
-    addslashes($body)));
+    addslashes(substr($body,0,1000000)))); # limit body of bounced message to 1 million bytes to avoid a MySQL max_allowed_packet limit

    ...


This fixes the problem for me. Hope this helps someone else.

Regards,
Tim Miller Dyck
Editor/Publisher
Canadian Mennonite
thdyck
phplist newbie
 
Posts: 4
Joined: 5:30am, Sun 06 Jan, 2008
Location: Waterloo, ON, Canada

Postby H2B2 » 8:45pm, Thu 21 Feb, 2008

Thanks for posting this! Should be quite useful info for the development team.
H2B2
phpList Guru
 
Posts: 6566
Joined: 1:51am, Wed 15 Mar, 2006

set session code editing...where do i do that?

Postby Guest » 2:36am, Tue 13 Jan, 2009

But how do I get to the place where I would do a set session and edit the code?

I have no idea how to do this...

Can you give me some direction, I'm getting the same error on my site!
Guest
 


Return to Answers, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 0 guests