How to compress base64 string in php

2.2k Views Asked by At

I have a web application. When upload an image to server I has converted that to base64 string, but when I inserted that to database is show an error "MySQL server has gone away". Because image string is to long, I think. So I tried using "$compressed = gzdeflate($param['image'], 9);" to compess that but not success. Anyone can help me to fixed it ?

Thanks for your time ?

1

There are 1 best solutions below

6
On

The MySQL server has gone away (error 2006) has two main causes and solutions:

  • Server timed out and closed the connection. To fix, check that “wait_timeout” mysql variable in your my.cnf configuration file is large enough.
  • Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection.

To fix, you can increase the maximal packet size limit max_allowed_packet in my.cnf file, eg. set max_allowed_packet = 128M, then sudo /etc/init.d/mysql restart.

The max_allowed_packet variable can be set globally by running a query.

SET GLOBAL max_allowed_packet=1073741824;

To change the setting for everyone until the server restarts