Thread

Posted on Tue Aug 29 17:19:17 2006 by aloknath251
Explorer crashing while writing into XML
Hi, I have this web page which saves data in an xml. The web page has 3 textfields which takes input and has a submit button.The data is saved in an XML when pressed the submit button. I am using CGI module for web page and XML::twig module to save the data. Sometimes I have observed while saving the data the explorer crashes.If the XML is opened using explorer, its always crashing probably while writing into it. Can anybody point out what is wrong ? Is there any way I can capture the exceptions ? One more question , do I need to use any locking mechanism while writing into the XML ? Thanx, Alok
my $registerFile = "Register.xml" ; my $twig = XML::Twig->new( pretty_print => 'indented' ); $twig->parsefile( $registerFile ); #This is the code to save and write into the XML if (pressed submit button execute this) { my $node = XML::Twig::Elt->new( 'User', {'name' => $usr}, XML::Twig::Elt->new( 'email' => $email )) ; $node->paste( last_child => $twig->root ) ; $twig->print_to_file( $registerFile ) ; print "<h3> Saved Successfully !! </h3>" ; }
Direct Responses: 2860 | Write a response
Posted on Tue Aug 29 17:54:25 2006 by mirod in response to 2858
Re: Explorer crashing while writing into XML

It is hard to answer without knowing what's the error message. Did you have a look at the logs? From the code you're showing, it doesn't look like a problem with XML::Twig, but who knows.

And yes, if several instances of your script are likely to be active at the same time and write the same file, then you need to lock it.

Direct Responses: 2874 | 2875 | Write a response
Posted on Thu Aug 31 16:10:43 2006 by aloknath251 in response to 2860
Re: Explorer crashing while writing into XML
Hi, I have added the following lines of code for locking the file. I see a new problem after the following code is executed, the XML file is completely blank. If I remove the file locking code the XML is atleast populated. However the xplorer still used to crash -both with file locking and without file locking. Can any one point out what is wrong in this code ? Or how to debug ? I am using IIS web server.
# Save user name and email # Inserting the submitted info my $node = XML::Twig::Elt->new( 'User', {'name' => $usr}, XML::Twig::Elt->new( 'email' => $email )) ; $node->paste( last_child => $twig->root ) ; #use lock to write into the file sysopen( FH, $registerFile, O_RDWR ) or die "can't open $registerFile: $!"; flock( FH, LOCK_EX) or die "can't lock filename: $!"; truncate(FH, 0) or die "can't truncate filename: $!"; $twig->print_to_file( $registerFile ) ; close(FH)
Direct Responses: 2876 | Write a response
Posted on Thu Aug 31 16:18:28 2006 by aloknath251 in response to 2860
Re: Explorer crashing while writing into XML
Hi, I have added the following lines of code for locking the file. I see a new problem after the following code is executed, the XML file is completely blank. If I remove the file locking code the XML is atleast populated. However the xplorer still used to crash -both with file locking and without file locking. Can any one point out what is wrong in this code ? Or how to debug ? I am using IIS web server.
# Save user name and email # Inserting the submitted info my $node = XML::Twig::Elt->new( 'User', {'name' => $usr}, XML::Twig::Elt->new( 'email' => $email )) ; $node->paste( last_child => $twig->root ) ; #use lock to write into the file sysopen( FH, $registerFile, O_RDWR ) or die "can't open $registerFile: $!"; flock( FH, LOCK_EX) or die "can't lock filename: $!"; truncate(FH, 0) or die "can't truncate filename: $!"; $twig->print_to_file( $registerFile ) ; close(FH)
Write a response
Posted on Thu Aug 31 16:24:48 2006 by mirod in response to 2874
Re: Explorer crashing while writing into XML

What do the logs tell you? As long as you don't look at the error file, your debugging is going to be just taking shots in the dark.

BTW, does flock work on Windows?

The last time I used locking (a while ago), I did not lock the file itself, but used a dedicated lock file:

use Fcntl; my $LOCK_FILE= "db.lock"; open LOCK, ">$LOCK_FILE" || die "Can't open lock file\n"; flock( LOCK, LOCK_EX) || die "Error $ERRNO during lock\n";

Does this help?

Direct Responses: 2882 | Write a response
Posted on Thu Aug 31 17:52:30 2006 by aloknath251 in response to 2876
Re: Explorer crashing while writing into XML
Hi mirod, i am using iis .The log information generally contains messages like .. which is not useful. 14:32:04 16.150.210.5 GET /scripts/Register.pl 200 14:32:15 16.150.210.5 GET /scripts/Register.pl 200 14:33:17 16.150.210.5 GET /scripts/Register.pl 200 14:33:37 16.150.210.5 GET /scripts/Register.pl 200 14:34:43 16.150.210.5 GET /scripts/Register.pl 200 The other concern is why my xml is wiped out when I enable file locking ?? I am lost. ~Alok
Write a response