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.
4 2608 prn 254
Expert 100+
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
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".
prn 254
Expert 100+
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Latio |
last post by:
Have a database that records data taken in the field and was using an
"auto_incremented" integer. I now want to distribute the database to others
so they can record data then centralise all the...
|
by: Hasani \(remove nospam\) |
last post by:
The way the system works is, you create a user control (ascx) that will be a
template and must implement the interface IPageTemplate. You then create one
or more user controls (ascx) that implement...
|
by: rayala |
last post by:
Hi all,
I am having very weird problem in my Outlook
I am running my web application from with in Outlook.I found a strange
problem that it is creating different sessionId if i open a new...
|
by: Michel Verhagen |
last post by:
Hi,
I want to create a DTD in an XML file in memory. The XML file is created
using the DOM in C#. I am new to all this, but couldn't find anything
about creating DTD's using the DOM (well, I...
|
by: Danny Liberty |
last post by:
I need some opionions on an issue here...
Suppose I want to keep a collection of objects, each need to be
uniquely identified by a number. This number has no meaning as long as
it's unique, so it...
|
by: Ronsol |
last post by:
Hi,
I want to import a XML file into SQL.
But i can't find a good example to create an unique id from an higer element.
I can create different tables, but a link between them not. I want to...
|
by: gamernaveen |
last post by:
I am coding a script , where basically the user has to enter his name , choose file , file comments if required and upload.
The file comments , name , filename will be stored in the database with...
|
by: Inny |
last post by:
Hello,
I found this simple js star rating script that I want to modify slightly.
firstly I want to retain current vote , say 3 stars, untill its changed again.
right now it resets to unvoted...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |