php execute a large number of sql statement MySQL server has gone away

php set timeout in seconds

set_time_limit(3600);
 
php memory limit set
ini_set ( 'memory_limit', '1024M ');
 
mysql server receives the packet size setting is not set newspaper  MySQL server has gone away error

Check the value of max_allowed_packet

show global variables like 'max_allowed_packet';

+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+

Can see the size of the default only 4M, the next value is set to 150M (1024 * 1024 * 150)

set global max_allowed_packet=157286400;

Until then view the size

show global variables like 'max_allowed_packet';

785e20e2ec81938375070e548b408d55.png

Note: The command line is only valid for the current settings, and then restart the mysql service to restore the default values, but you can modify the configuration file (you can add max_allowed_packet = 150M in the configuration file to the my.cnf) to achieve the purpose of permanent

 

Guess you like

Origin www.cnblogs.com/xuey/p/11545299.html