lunes, 11 de noviembre de 2013

Cambiar timeout en php

Un programa en php que tiene que hacer muchas operaciones con la base de datos (lo cual tarda un tiempo considerable ya que hace un merge de una base grande casi completa) me tiraba el error...

Fatal error: Maximum execution time of 30 seconds exceeded in xxxx

Para arreglar el problema desde PHP le defino mas time_limit al script usando la función

set_time_limit(600);


... que limita el tiempo máximo de ejecución del script... acá más info: http://php.net/manual/es/function.set-time-limit.php

Cómo setear variables globales en MySQL

Desde línea de comandos (consola linux)...




#>mysql -uroot -e "show variables like '%timeout';" -p
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| connect_timeout            | 10    |
| delayed_insert_timeout     | 300   |
| innodb_lock_wait_timeout   | 50    |
| innodb_rollback_on_timeout | OFF   |
| interactive_timeout        | 28800 |
| net_read_timeout           | 30    |
| net_write_timeout          | 60    |
| slave_net_timeout          | 3600  |
| table_lock_wait_timeout    | 50    |
| wait_timeout               | 28800 |
+----------------------------+-------+ 
10 rows in set (0.00 sec)
#>mysql -uroot -e "SET GLOBAL net_read_timeout=600;" -p 
#>mysql -uroot -e "show variables like '%timeout';" -p
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| connect_timeout            | 10    |
| delayed_insert_timeout     | 300   |
| innodb_lock_wait_timeout   | 50    |
| innodb_rollback_on_timeout | OFF   |
| interactive_timeout        | 28800 |
| net_read_timeout           | 600   |
| net_write_timeout          | 60    |
| slave_net_timeout          | 3600  |
| table_lock_wait_timeout    | 50    |
| wait_timeout               | 28800 |
+----------------------------+-------+ 
10 rows in set (0.00 sec)

Listo!
:-P