2011-09-01 3 views
3

나는 웹 서버에서 겪고있는 문제에 도움을 줄 수있는 사람을 찾고 있습니다. 현재 서버는 헬프 데스크에서 구매 한 웹 응용 프로그램을 호스팅합니다. 8 시간마다 누군가는이 오류가 나타납니다 페이지로 이동할 때 : 나는 /etc/my.cnf에 파일 즉,의 최대 값으로 아웃 (wait_timeout)의 설정을 시도[경고] : PDO :: __ construct() : MySQL 서버가 사라졌습니다 - wait_timeout이 원인이 아닙니까?

[Warning]: PDO::__construct(): MySQL server has gone away (Database/class.SWIFT_Database.php:334) 

;

또한 mysql에서 전역 wait_timeout을이 값으로 설정하고 세션 wait_time을 동일하게 설정했습니다.

mysql 서비스를 다시 시작하면 대기 시간 초과가 my.cnf에 설정되어 있음에도 불구하고 28800 기본값으로 재설정됩니다. 누군가가 방향으로 나를 가리킬 수 있는지보고 행복해 비록 mysql에 대한 다른 구성 파일을 찾을 수 없습니다.

또한 오늘 아침에 서버에 로그인하여 다음 명령을 실행하면 세션의 wait_timeout 값이 되돌려졌습니다.

mysql> select @@global.wait_timeout, @@session.wait_timeout; 
+-----------------------+------------------------+ 
| @@global.wait_timeout | @@session.wait_timeout | 
+-----------------------+------------------------+ 
|    31536000 |     28800 | 
+-----------------------+------------------------+ 
1 row in set (0.00 sec) 

나는이 다양한 웹 어플리케이션이 MySQL을 실행하는 온라인 많은 사람들에 대한 문제라고 볼 수 있지만 아무도 수정을 것 같다. 많은 조언을 온라인 wait_timeout 가리 킵니다하지만 그것은보고있는 버그를 변경하는 것 같지 않습니다. 나는이 문제에 관한 MySQL 매뉴얼의 수정을 시도했지만, 여전히 행운은 없다. (링크 : http://dev.mysql.com/doc/refman/5.0/en/gone-away.html)

어떤 조언을 주시면 감사하겠습니다.

서버 : 아래의 서버 세부 사항 및 제품 버전 오픈 수세 11.4 MySQL 버젼 : 사전에 5.1.53

많은 감사합니다! Drupal.org에

답변

1

This article가 현재 상황에서 유용 할 수 있습니다

MySQL comes with a default configuration of the resources it is going to use, specified in "my.cnf" (Linux) or "my.ini" (Windows) during the installation of MySQL.

In Linux this file is located at /etc/my.cnf to set global options, or /usr/local/var/mysql-data-dir/my.cnf to set server-specific options.

In Windows this file is located by default at C:\Program Files\MySQL\MySQL Server X.Y\my.ini .

Resources allowed by the default configuration are normally insufficient to run a resource-intensive application. You must modify the following resource specifications if they are available in your original configuration file, or add them to the configuration file if they are not already specified (because some are not present by default) :

Important: Remember to keep backup files before you do anything! You will also have to reload the MySQL service after making changes to these configuration files.

MyISAM specifications:

[mysqld] 
port = 3306 
socket = /tmp/mysql.sock 
skip-external-locking 
key_buffer = 384M 
max_allowed_packet = 64M 
table_cache = 4096 
sort_buffer_size = 2M 
read_buffer_size = 2M 
read_rnd_buffer_size = 64M 
myisam_sort_buffer_size = 64M 
thread_cache_size = 8 
query_cache_size = 32M 

InnoDB specifications:

innodb_buffer_pool_size = 384M 
innodb_additional_mem_pool_size = 20M 
innodb_log_file_size = 10M 
innodb_log_buffer_size = 64M 
innodb_flush_log_at_trx_commit = 1 
innodb_lock_wait_timeout = 180 

Note: It is assumed here that you are using the InnoDB database tables, as Drupal is a resource intensive application. If you are not using the InnoDB database tables try to change this, in view of the fact that you are getting the Warning: MySQL server has gone away - apparently meaning that your setup is resource intensive.

5

동안 매우 우아하지, 다음 코드는 나를 없애 도움이되었습니다 시간 초과 및 지속적인 연결 유지. 문제가 시간 초과 된 경우 최대 1 회만 시도하면되지만 행에 $ 제한 횟수가 초과되면 예외가 발생합니다.

$db = null; 
$limit = 10; 
$counter = 0; 
while (true) { 
    try { 
     $db = new PDO('mysql:host=' . db_host . ';dbname=' . db_name, db_user, db_pass); 
     $db->exec("SET CHARACTER SET utf8"); 
     $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); 
     $db->setAttribute(PDO::ATTR_PERSISTENT, true); 
     break; 
    } 
    catch (Exception $e) { 
     $db = null; 
     $counter++; 
     if ($counter == $limit) 
      throw $e; 
    } 
} 
+0

! 지속적인 연결을 유지해야했습니다. 여전히 while() while 루프를 사용하는 것을 주저합니다. 찬반 양론에 대한 의견이 있으십니까? – Hafenkranich

1

연결이 닫히는 데는 여러 가지 이유가 있습니다.

참조 : https://dev.mysql.com/doc/refman/5.0/en/gone-away.html

내가 너무 그 분 이상자는 경우 호스팅 관리자가 연결을 죽이고 PDO를 사용하여 유사한 문제에 직면했다. 그래서 나는 PDO 수업을 감싸는 수업을 시작했다. 그러면 연결이 닫혔는지 여부가 감지되고 쿼리 실행시 다시 연결을 시도합니다.

대답

아래 실제로 작동

PDO: MySQL server has gone away

+1

이 링크는 질문에 대답 할 수 있지만 답변의 핵심 부분을 여기에 포함시키고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. – MZaragoza

+0

왜 downvote. 나는 이미 비슷한 질문에 답했다. – mysticmo

관련 문제