polygon
asked on
Start an asyncronous script from a cgi page?
I need to start a script that runs for a few hours using a cgi page. I can simply run the script from the browser, but the user will have to wait these few hours (and will most probably time out) and I don't want this. I want to be able to just run the script independantly of the browser...
Is there a way to do this? Say, can I schedule a cronjob with a cgi page? Or is there another solution?
Is there a way to do this? Say, can I schedule a cronjob with a cgi page? Or is there another solution?
ASKER
The cronjob thing works fine for me... But how do I set up a cronjob from within a cgi page (this may be a trivial question, but I am not much into Perl now :))).
I need to be able to set the cronjob to run at the moment (or maybe a few seconds after) the user clicks "Start the job" link...
I need to be able to set the cronjob to run at the moment (or maybe a few seconds after) the user clicks "Start the job" link...
ASKER
The cronjob thing works fine for me... But how do I set up a cronjob from within a cgi page (this may be a trivial question, but I am not much into Perl now :))).
I need to be able to set the cronjob to run at the moment (or maybe a few seconds after) the user clicks "Start the job" link...
I need to be able to set the cronjob to run at the moment (or maybe a few seconds after) the user clicks "Start the job" link...
polygon,
which OS your CGI runs on?
which OS your CGI runs on?
Let me get this strait.. you want to put a scheduled task onto the system using perl ?
Well, your obviously using a unix based system the files you need to edit are in /var/spool/cron - something like that.
You can definately edit this file with perl - should not be a problem as long as your permissions are set up correctly - however this is not generally a good idea and i would advise against it.
Cheers
Mehdi
Mehdi
Well, your obviously using a unix based system the files you need to edit are in /var/spool/cron - something like that.
You can definately edit this file with perl - should not be a problem as long as your permissions are set up correctly - however this is not generally a good idea and i would advise against it.
Cheers
Mehdi
Mehdi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hmm, i see what you are saying now..
im thinking - change the system time using perl - forcing your cronjob to gogo.. then set it back - your other process is underway and bobs your uncle..
That is a real HACK, but should work i think.
Im sure there is a better way to do it.. but cant think of it right now..
Mehdi
im thinking - change the system time using perl - forcing your cronjob to gogo.. then set it back - your other process is underway and bobs your uncle..
That is a real HACK, but should work i think.
Im sure there is a better way to do it.. but cant think of it right now..
Mehdi
Hmm, i see what you are saying now..
im thinking - change the system time using perl - forcing your cronjob to gogo.. then set it back - your other process is underway and bobs your uncle..
That is a real HACK, but should work i think.
Im sure there is a better way to do it.. but cant think of it right now..
Mehdi
im thinking - change the system time using perl - forcing your cronjob to gogo.. then set it back - your other process is underway and bobs your uncle..
That is a real HACK, but should work i think.
Im sure there is a better way to do it.. but cant think of it right now..
Mehdi
polygon,
Ive had a thought.
Why dont you change the way your program works altogether.
You are obviously carrying out a lengthy procedure based on user interaction through cgi.Your already asking the user to come back later (when the process completes) so why not do it this way,
* Get the user input and store it as "un-processed entries", tell the user to come back later, say an hour.
* set up a crongjob to run on the server every 30 minutes or so to process the unprocessed entries.
* When the cronjob is run, it processes "un-processed" entries and marks them as "processed".
* When the user returns they are shown the result of the processed entry (if its processed). If the entry is not yet processed, they are told to come back later.
Hope that helps, though its not so much a solution - more a work around, but i think it achieves the same thing.
Mehdi
Ive had a thought.
Why dont you change the way your program works altogether.
You are obviously carrying out a lengthy procedure based on user interaction through cgi.Your already asking the user to come back later (when the process completes) so why not do it this way,
* Get the user input and store it as "un-processed entries", tell the user to come back later, say an hour.
* set up a crongjob to run on the server every 30 minutes or so to process the unprocessed entries.
* When the cronjob is run, it processes "un-processed" entries and marks them as "processed".
* When the user returns they are shown the result of the processed entry (if its processed). If the entry is not yet processed, they are told to come back later.
Hope that helps, though its not so much a solution - more a work around, but i think it achieves the same thing.
Mehdi
Poly,
Have you tried executing $test = `command.pl &`; ? note the backticks - execute a system command... the "&" should make it run in the background.
M
Have you tried executing $test = `command.pl &`; ? note the backticks - execute a system command... the "&" should make it run in the background.
M
There is no reason why a cronjob would not work on your actual script. Just beware that the execution of your code is not dependant on things such as:
* URL - your not passing parameters to the script with a GET string
* SERVER_NAME, and other environment variables which are quite often used from CGI scripts.
Hope that helps
Mehdi