I am writing a server that connects to MySQL via DBI (driver and/or ODBC). I have appended a piece of simplified test code illustrating the problem. Here are my observations.
- Problem only occurs under Windows (Win2K) and never under Unix (FreeBSD). - Any child fork that connects to MySQL after another child fork has connected, disconnected and exited will generate an address fault. - Child forks may connect to MySQL without error, as long as no child fork has exited. - Effect is identical for DBI:MySQL and DBI:ODBC:MyODBC-DSN. Thanks for any help. ____________________________________ #!/usr/local/bin/perl # Usage: perl testForkDBIMySql.pl # Test script creates 3 to 5 child processes, each identical which open DBI connection # to MySQL, sleep, close connection and potentially exit. As configured, will create # memory address error under Win2K after 2-second task exits. See inline comments for # testing options. use strict; use DBI; my $user = your_username_here; my $pass = your_password_here; sub serviceTask { my ($time) = @_; print "$$ Child $time starting ".gmtime()."\n"; # Comment out one or other of connect statements; shouldn't alter result. my $dbh = DBI->connect("DBI:mysql:iView", $user, $pass); # my $dbh = DBI->connect("DBI:ODBC:MySQL-ODBC", $user, $pass); print "$$ Child $time started ".gmtime()."\n"; if ($dbh) { sleep $time; print "$$ Child $time ending ".gmtime()."\n"; my $rc = $dbh->disconnect; print "$$ Child $time ended ".gmtime()."\n"; } # Uncomment the sleep to prevent child processes from exiting. Should prevent # memory errors. # WARNING: Child processes will not die and memory will not be released # sleep (10) while (1); print "$$ Child $time exit ".gmtime()."\n"; } # Delete " = 1" for case where all children start before any exits. Should avoid # starting new child after another child has exited. my $earlyExit = 1; my @times = $earlyExit ? (2, 3, 5, 7, 11) : (5, 7, 11); print "$$ Parent start ".gmtime()."\n"; foreach my $time (@times) { my $pid; if (!defined($pid = fork)) { print "Cannot fork: $!"; } elsif ($pid) { print "$$ Parent $time fork ".gmtime()."\n"; } else { exit &serviceTask($time); } sleep 1; } print "$$ Parent end ".gmtime()."\n"; 1 --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php