|
-
CGI/Perl Threading Problems!!
I have encountered a very interesting browser-specific problem with CGI/Perl.
My script is well over a hundred lines, but I will outline its general structure as follows:
# if the target file exists, abort
if(-e "newfile.html")
{
&Error("newfile already exists!")
}
#else open a new file for write access
if(open (FILEHANDLE, ">newfile.html") == 0)
{
&Error("Couldn't open newfile.html");
}
# print a bunch of stuff to the file
print FILEHANDLE ....
print FILEHANDLE ....
# print a message to stdout to indicate #success
Here's the oddity. This works well in Netscape. I get the success message on my screen. HOWEVER, In IE I ALWAYS GET THE NEWFILE ALREADY EXISTS ERROR!
I erase the file, run the CGI script, and escape with the "file exists" error. I then look on the server, and the file has actually been successfully created. So it looks as if the CGI server spawns a slow thread that checks for the file existence. In the meantime, a fast thread performs the subsequent commands and creates the file. Then all of a sudden the slow thread says, "I can't go on. This file already exists!" Does Perl use threading like this? Why in the world would the CGI server run the script differently for different browsers!?
I'd love to hear any ideas or similar encounters.
-
based on what you said, it seems odd:
1) Make sure the directory is set to writable
2) Make sure the version of PERL isnt a buggy beta version.
------------------
DHAHL3seasons GP:73 G:121 A:55 Pts:176 GWG:12 +/-:184
UWSWA1season GP:9 G:12 A:8 Pts:20 GWG:3 +/-:-3
uwcdc.com or namgor.com
DHAHL3seasons GP:73 G:121 A:55 Pts:176 GWG:12 +/-:184
UWSWA6seasons GP:41 G:53 A:46 Pts:99 GWG:5 +/-:-25
MCBHL3seasons GP:14 G:20 A:8 Pts:28 GWG:4 +/-:19
uwcdc.com or monkis.com
-
Originally posted by namgor:
based on what you said, it seems odd:
1) Make sure the directory is set to writable
2) Make sure the version of PERL isnt a buggy beta version.
Oefinger responses:
(1) The directory is indeed writable. In fact, as I said above, the writes are taking place. However, they take place BEFORE the test completes to see if the file exists!
For example, my code has two steps:
a) if <filename> exists then die
b) else open <filename> for write access and write some html to it
I look in the directory to make sure NO files exist. Then I run the CGI script from an IE client. I get an error message saying the file already exists. When I look in the directory, sure enough, there is a new file created by my script. So b)happens BEFORE a)!!
THIS DOES NOT HAPPEN WHEN I USE NETSCAPE!
(2)
I am using v5.6.0, the standard release with RedHat 7.0.
Any ideas?
Thanks!
-
UPDATE:
I performed a quick test to see how many times the script is executing. It turns out that the script executes twice when called by IE, and once when called by NS. Since my code is written as:
if <filename> exists die
else open <filename>
The code dies on the second execution. I have NO idea why the code executes a second time on IE. I have no browser-type checks on the server-side CGI script, so somehow the IE browser is interpreting the "submit form" button click as two clicks. I do NOT mess with button_up and button_down functionality, so it is not possible that I forced a double-send with a javascript. WEIRD!
Any ideas?
Thanks!
-
FIXED:
The problem had nothing to do will Perl threading. The problem lay in the JavaScript.
My JavaScript code for OnSubmit looked like:
if <form is valid>
{
form.submit()
window.close()
}
In Netscape, this simply submits the form and closes the window. In IE, however, this submits the form, closes the window, then returns TRUE to the source HTML page. Since the source HTML page has a CGI action associated with its form, it then submits the form (after the JS just submitted it!)
The workaround: simply add
return false
after form.submit.
The return false ensures that the form that called the JS does NOT submit the form (because false indicates that the form is invalid)
-
The proper way to fix the JS would be to not form.submit(). Instead of returning false. Letting the browser do what is natural will help you in the long run, I guaruntee it.
*edit* To be more specific:
Code:
if (valid())
return true
else
return false
------------------
Advocate of the Sharky (Ultra) High-Resolution Club [SHRC]
main(i){putchar(341513875>>(i-1)*5&31|!!(i<6)<<6)&&main(++i);}
[This message has been edited by reklis (edited July 13, 2001).]
Advocate of the Sharky (Ultra) High-Resolution Club [SHRC]
main(i){putchar(341513875>>(i-1)*5&31|!!(i<6)<<6)&&main(++i);}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|