Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

superbovine

macrumors 68030
Original poster
Nov 7, 2003
2,872
0
ok, I have a script running see cowzilla in my sig that will use cURL to download a xml file and store in a cache file then parse the stored file. Recently I added a line of code to create a unique cache file name every time the script is run because the old ver just used the same file name for each instance the script was run.

My question is weather or not that line was needed or advisable. If there are more than one instance using that script will the the second instance of the script wait for the first instance to run or does it will on unix to decide who gets to write/read/edit the file? My other question is weather or not having unique cache file names will actually speed up the script when multiple users are using because the process won't have to wait for another process to use the file.

I haven't really check online for the answer, but none of my reference books address this issue.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
i'm not certain i grok your whole question, but i read one part like this:

"in unix, if the same user account invokes a script, will it launch immediately or will it wait?"

if that's the question, the answer is that another process will indeed fork off, with its own runtime memory space, and run concurrently with the others.

where you need to be concerned with conflicts is when the script does something outside that memory space, such as writing to a database or writing/creating files.

for your situation, where the script creates a file for that instance, i'll ask how you decide the name of that file. if you want to keep those files distinct for each instance, you'll need some kind of unique identifier. you don't say what scripting language you're using (or i missed it), but when i do such things in Bourne shell i simply use $$, which gives me the process id (pid). since pid's are unique, the filename will be unique.

this example creates two unique files:
Code:
#!/bin/sh

FILE1=/tmp/foo$$
FILE2=/tmp/bar$$

touch $FILE1 $FILE2
is this the kind of info you're looking for?
 

superbovine

macrumors 68030
Original poster
Nov 7, 2003
2,872
0
I generate the id by this:

PHP:
$cache_name = md5(uniqid(rand(), true));
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
do i have it right that a number of users will be connecting to your webserver, requesting a service, and that service will result in writing a uniquely-named file to your directory?

if so, is there any need to handle a specific user, let's call him User A, making re-entrant calls to your server and needing access to 'his' file over and over again?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.