Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Perl: Системное программирование > DBI::mysql и fork'и


Автор: Ramirez 22.8.2005, 22:52
День добрый! До этого не приходилось связываться с форками, но вот пришлось. Скрипт использует, DBI::mysql. И вот что мне выдает: MySQL server has gone away.


Содержание примерно такое:
Код

#!/usr/bin/perl

use DBI;

our $DBH = DBI->connect($DSN,"user","pass",{ RaiseError=>0,AutoCommit=>1 }) or die "Can't connect to database"; 

.........

unless($child = fork) {                                                                                                             
        print "(pid $$)\n";                                                                                                         
        while(1) {                                                                                                                  
            my %msg = SQL->buildHash("SELECT icq,message FROM events WHERE status = 0",$DBH);                                       
            SQL->write("UPDATE events SET status = 1 WHERE status = 0",$DBH) if %msg;                                               
            foreach (keys %msg) {                                                                                                   
                send_text_message($_, $msg{$_});                                                                                    
            }                                                                                                                       
            driver_executor();                                                                                                      
            sleep 1;                                                                                                                
        }                                                                                                                           
}  


Я так понимаю, где-то теряется идентифткатор соединения. Есть какие-то тонкости при использовании форков?

Спасибо.

Автор: Ivan Kolesnikov 23.8.2005, 02:43
Посмотрев документацию на DBI я наткнулся на одну опцию при коннекте: InactiveDestroy
Цитата

The C<InactiveDestroy> attribute can be used to disable the I<database engine> related
effect of DESTROYing a handle (which would normally close a prepared
statement or disconnect from the database etc).

For a database handle, this attribute does not disable an I<explicit>
call to the disconnect method, only the implicit call from DESTROY.

The default value, false, means that a handle will be automatically
destroyed when it passes out of scope.  A true value disables automatic
destruction. (Think of the name as meaning 'inactive the DESTROY method'.)

This attribute is specifically designed for use in Unix applications
that "fork" child processes. Either the parent or the child process,
but not both, should set C<InactiveDestroy> on all their shared handles.
Note that some databases, including Oracle, don't support passing a
database connection across a fork.

Может быть поможет, сам проверить не могу, так как база только Oracle, а про него тут ясно написано smile

Автор: Ramirez 22.9.2005, 00:15
Да, действительно дело было в этом параметре. Респект =)

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)