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

scalability of perl cgi programs that load text files

P: n/a
MJL
Suppose you have a perl program that is called by a web page to
generate another web page. The program is written to load data from a
text file on the server and make certain substitutions in the loaded
text prior to the output of html.

If one user is on the site, it should not be a problem. If many users
try to access it nearly simultaneously, will it be a problem?

example:

file: text.txt

I am <adjective>.

file: process.perl

....
open INPUT, "./text".".txt";
@list = <INPUT>;
close INPUT;
foreach(@list)
{
s/<adjective>/stupid/g;
}
....

What happens here when a second user causes the program to run when
the first user is at the point where the text file is opened and not
yet closed?
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>Suppose you have a perl program that is called by a web page to
generate another web page. The program is written to load data from a
text file on the server and make certain substitutions in the loaded
text prior to the output of html. If one user is on the site, it should not be a problem. If many users
try to access it nearly simultaneously, will it be a problem?


That's what file locking is designed for.. look into flock()..

Regards,
Chris

P.S. You do realise this a PHP group ?
Jul 17 '05 #2

P: n/a
On 21 Aug 2004 22:33:08 -0700, ma**@affordablemedicalsoftware.com (MJL) wrote:
Suppose you have a perl program that is called by a web page to
generate another web page.
Suppose you post this Perl program to a PHP newsgroup... what is the expected
result? :-) Try comp.lang.perl.misc.
The program is written to load data from a
text file on the server and make certain substitutions in the loaded
text prior to the output of html.

If one user is on the site, it should not be a problem. If many users
try to access it nearly simultaneously, will it be a problem?
Not if it's read-only. If it's updated, then yes, you'll have multiple
processes stomping on each other's data, in which case you need to put locking
around it, or better, use a database, as concurrent access is one of the
several main reasons you'd use a database over a flat file.
example:

open INPUT, "./text".".txt";
You probably want to be specifying a filemode here - assuming you just want
'r' (read-only).
What happens here when a second user causes the program to run when
the first user is at the point where the text file is opened and not
yet closed?


Presumably operating-system dependent, but it would have to be a pretty duff
operating system to disallow read-only access to multiple processes.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3

P: n/a
MJL
> Regards,
Chris

P.S. You do realise this a PHP group ?


Oh, man. I am so embarrassed. Sorry. I have been so entangled in
playing with code in the two languages this weekend that I really
screwed up and posted to the wrong group. My perl script is
generating HTML and PHP. Sorry again.
Jul 17 '05 #4

P: n/a
"MJL" wrote:
Suppose you have a perl program that is called by a web page to
generate another web page. The program is written to load data from a text file on the server and make certain substitutions in the loaded text prior to the output of html.

If one user is on the site, it should not be a problem. If many users try to access it nearly simultaneously, will it be a problem?

example:

file: text.txt

I am <adjective>.

file: process.perl

....
open INPUT, "./text".".txt";
@list = <INPUT>;
close INPUT;
foreach(@list)
{
s/<adjective>/stupid/g;
}
....

What happens here when a second user causes the program to run when
the first user is at the point where the text file is opened and not yet closed?


This is a php newsgroup. Try a perl newsgroup for better coverage.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-scalabil...ict142045.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=475202
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.