By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,540 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

creating unique job id's for cgi script

P: 5
HI,

I am creating a web server in which user will upload a file, in my cgi script using the upload method i am getting the file handle and writing the file in my hard drive, later am using the written file to do some process (in which two other files will be created and the names of those files are hard coded) and will list the output for the end user.

my question is if i have released this server globally, i may get lots of files at a time and i think it will crash, so to avoid that i wish to allocate unique job id to users when they upload the file, i wish to do like this and i am wondering how to do this in my cgi script or to be done somewhere.

please help me to do this?

Mopi.
Jan 17 '08 #1
Share this Question
Share on Google+
4 Replies


prn
Expert 100+
P: 254
prn
Hi Mopi,

There are probably at least a billion ways to do this. Which you pick depends a lot on what you are trying to accomplish. Here's a simple one that should be moderately robust:

Assign IDs sequentially. You can start with any numbe you like. Create a file to contain the current job id. Your server process can then:
1) lock the file (flock).
2) open for read/write
3) read the current number
4) increment the number and keep track of that as your current id
5) save the new number
6) close the file
7) release the lock

Since the file is used only by your process, you should not need to worry excessively about whether your OS (windows?) will honor the file locks generally. Your process will. (The flock function reportedly does not work properly on Win95, but if you are using Win95 as a web server, you have much larger problems than I want to tackle.) The file will remain locked for only a very small fraction of a second, so this should not create any sort of server bottleneck. The numbers will be unique. Problem solved.

As I say, there are lots of other ways to solve the matter of assigning unique IDs. Many of them will work. You're probably much better off picking one that does check for uniqueness instead of just picking a random number and hoping that it will not cause a collision, but most of the time it won't. Timestamps are also good, but if you get a lot of traffic, then you had better take care to make sure that the granularity of your timestamp is sufficient.

HTH,
Paul
Jan 17 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
Good info Paul, but I am not sure it addressed his concern:

my question is if i have released this server globally, i may get lots of files at a time and i think it will crash,
Using a unique ID will not have any affect on how the server runs. It's doubtlful it would crash, but it might get very slow and be inaccessible if too many users are accessing the script. The http server setup is probably the place he needs to look to keep his server from "crashing".
Jan 17 '08 #3

prn
Expert 100+
P: 254
prn
Good point, Kevin. I think he was referring to name collisions rather than actual server crashes due to load, but that's a possible interpretation too.

I guess he can clarify if needed.

Paul
Jan 17 '08 #4

KevinADC
Expert 2.5K+
P: 4,059
Good point, Kevin. I think he was referring to name collisions rather than actual server crashes due to load, but that's a possible interpretation too.

I guess he can clarify if needed.

Paul

Hopefully he will clarify.
Jan 17 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.