forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


More CGI Help needed

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up
View previous topic :: View next topic  
Author Message
DavidR
Contributor
Contributor


Joined: 05 Aug 2003
Posts: 83
Location: Bethel Pennsylvania U.S.A.

PostPosted: Tue Nov 23, 2004 1:54 am    Post subject: More CGI Help needed Reply with quote

I've learned a great deal about CGI programming by reading the Posts here but there's one thing I've not quite figured out. Here goes!
My main page runs report.exe on the server that kicks off a rather complex report. Since it may take a while to finish the report I return a message to the user asking them to wait. This page calls a "check.exe" program every 5 seconds that looks for the reports "output" file. If it finds the file it returns it to the user, otherwise it does nothing and the wait page checks again in 5 seconds. So far so good!
Only one iteration of the report can run at a time so when the report starts (the report is a non VDS program) I write a flag file so other users attempting to run the report will get a message telling them that someone else is accessing the report system, try later. The flag file gets deleted by the check.exe program when it returns the report results to the user.
The problem happens when the user gets tired of waiting and closes the browser before the report is finished. The check.exe doesn't run and the flag file stays in place preventing other users from running the report.
Here is the question. Is there any way for a CGI program to detect that the user has closed their browser? Or perhaps there's a better way to approach this.
Anybody have any ideas?
Back to top
View user's profile Send private message
PGWARE
Web Host


Joined: 29 Dec 2001
Posts: 1565

PostPosted: Tue Nov 23, 2004 6:01 am    Post subject: Reply with quote

Its been awhile since I've used a windows server and created vds cgi's so I'll try to be as helpful as possible Smile

When the report runs it creates a file that contains a flag that basically says a report is in progress thus no one else can load/view the reports until the user logged in is done.

Now the check.exe obviously is no longer executed every 5 seconds thanks to the person closing the browser, thus the flag file remains and never is deleted and in the process makes it appear to all other users checkign teh reports that someone is still logged in trying to run a report.

Now what you can do is if you have a rough idea of how long reports should run for your cgi can first (during login) check the date/time stamp of when the flag file was created. If for instances it more than 5 minutes ago then the report should have finished by then and the cgi script should delete the flag file and allow the new user access.

Not the best solution but one that can be added in with little coding I suspect since it only requires datetime checking during the login phase and checking against the flag file and it's creation date/time.
Back to top
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Tue Nov 23, 2004 8:41 am    Post subject: Reply with quote

You can also check if the VDS CGI file is still running by using a hidden window. If there isn't a hidden window with the title you specify, but the flag file is still there, you know the client closed his browser window. Here's a rough idea... Smile

Code:
if @file(flagfile.txt)
if @winexists("RUNNING")
  output "Sorry, somebody else is already working on it... Smile"
  exit
else
  output "Somebody has start running this, but closed his browser. Just delete the flagfile.txt, and continue running... Smile"
end
else
output "You're free to go... Smile"
end

dialog create,RUNNING
# create flagfile here

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Tue Nov 23, 2004 4:01 pm    Post subject: Reply with quote

Depending on the kind of access to the server you have, I used to log the
IP address and keep tabs of the current IP's visiting the server. If the IP
dropped off from the server itself, then I would kill the process and clean
up after the visitor and have it ready for the next.

-Garrett

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
DavidR
Contributor
Contributor


Joined: 05 Aug 2003
Posts: 83
Location: Bethel Pennsylvania U.S.A.

PostPosted: Tue Nov 23, 2004 4:20 pm    Post subject: More CGI Help needed Reply with quote

Thanks for the great responses!
I think I'm going to go with the timer idea since it requires the least amount of re-coding at this point.
Yes I can determine the maximum time for the largest report and put a "timeout" timer in my initial "report.exe" to compare file creation time with current time and delete the flag file if some user "bails out"
Very Happy Thanks again, I knew somebody would have a solution Very Happy
...........David
Back to top
View user's profile Send private message
DavidR
Contributor
Contributor


Joined: 05 Aug 2003
Posts: 83
Location: Bethel Pennsylvania U.S.A.

PostPosted: Wed Nov 24, 2004 1:27 pm    Post subject: Comparing current time with file creation time Reply with quote

Is there a "better" way to do this?
It works but it seems like I must be overlooking an easier way.
Code:

OPTION DECIMALSEP,"."
IF @FILE(C:\testfile.txt)
%%AGE = @FINT(@FMUL(@FSUB(@DATETIME(),@FILE(C:\testfile.txt,T)),1000))
      IF @GREATER(%%AGE,3)
         REM File is an orphan, delete and start report
         FILE DELETE,C:\testfile.txt
         GOTO REPORTSTART
      END
END
:reportstart
EXIT

Thanks........
..........David
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Wed Nov 24, 2004 2:02 pm    Post subject: Reply with quote

I'd go for:

Code:
if @greater(@FSUB(@DATETIME(),@FILE(C:\testfile.txt,T),0.0003))


it seems simpler.

Except I wouldn't put the @file function in the sum at all, as there is a slim chance that the file could be deleted between lines 2 and 3 of your example.

_________________
The Tech Pro
www.tech-pro.net
Back to top
View user's profile Send private message Visit poster's website
DavidR
Contributor
Contributor


Joined: 05 Aug 2003
Posts: 83
Location: Bethel Pennsylvania U.S.A.

PostPosted: Wed Nov 24, 2004 2:17 pm    Post subject: Reply with quote

jules wrote:
I'd go for:

Code:
if @greater(@FSUB(@DATETIME(),@FILE(C:\testfile.txt,T),0.0003))


it seems simpler.

Except I wouldn't put the @file function in the sum at all, as there is a slim chance that the file could be deleted between lines 2 and 3 of your example.


Yep that's simpler alright!
Not much chance of the file being deleted, the delay is long enough that by the time we get to this point we're pretty sure the user "bailed out" on us.

Thanks for the help..
..........David
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group