Mysql – “Mysql has gone away” heavy multiple insert

insertMySQLPHP

I am stuck because Mysql server will go away after executing this part of code this function will update the database with the new RSS feeds which are stored in ToUpdate but Mysql stops working. Every cell of the array contains a long string for description,for example at the size of 3000 words or more and may be that's the problem. the maximum size of $this->array_counter is less than 30 and is set before in another function. after running the function after 3 to 6 inserts mysql says " mysql has gone away". Is the problem related to connection limit or bandwidth limit or fast inserting?

function update_db()
{


    for($i = 0;$i < $this->array_counter ; $i++ ){

        $url=$this->toUpdate[$i]['url'];

         $t=addslashes( $this->toUpdate[$i]['title'] );
         $t=$this->convert_line_breaks($t,"<br/>");

         $d=addslashes( $this->toUpdate[$i]['desc'] );
         $d= $this->convert_line_breaks($d,"<br/>");

         $date= $this->toUpdate[$i]['date'];

    //echo "<fieldset>".$url."<br/>".$t."<br/>".$d."</fieldset>";

        $r=mysql_query("INSERT INTO feed_items(items_id,items_title,items_url,items_description,items_date,feed_id,like_hits) VALUES('','$t','$u','$d','$date','$this->Feed_id','0') ",$this->dblink)or die(mysql_error());

    }//end of foreach
}

Best Answer

I usually blame the size of your MySQL Packet

I have written past posts on this

Just raise your MySQL Packet size (max_allowed_packet) in /etc/my.cnf

[mysqld]
max_allowed_packet=256M

and restart mysql