Concurrent Read-Access of Text File

I have a PHP script that reads and displays several lines from a static text file (about 5MB at this stage) on the web server. The script does NOT write to the text file.

Are there likely to be issues if many page visitors access the script at about the same time ? Would there be read-access issues and/or would the display of data from the text file be garbled?

Thanks

I don’t foresee issues with reading it even with multiple users at once. The part that is concerning is the file size. Even though they are not going to see this file in the browser, they still need to technically download it while loading the page and at 5mb that’s a huge file for a web page to load, heck a page that loads 1mb of data is usually way to big.

Thanks for responding. I had the impression that since the script and text file (and the array that the text file is read into) are on the server-side, the client would be spared any downloading time (?) i.e.

$lines = file(“textfile.txt”); //file into an array
echo $lines[998]; //line 999

Would something like this take the strain of many concurrent visitors?

I agree with Fastsol again on this one. If you have a website page that loads the file, it is loaded for EACH
of the user’s that are going to that page. If there are 10 people, no problem. If there are 1000, again, it
means loading that 5Megs times 1000 user’s. There are ways to cache a file on a server so it is not re-read
over and over, but, that can be tricky.

Why not use a simple MySQL table and break up the lines and query only what you need to view?

Perhaps a little more info on why you are using text files for display might help us further?

Get what you’re saying now - speed impacts on the server side translates to speed impacts on the client side as the number of concurrent users increases.

The text file is a bank of questions which the script would randomly pick a few from for every page visitor. To minimise server load, I’ll create a separate script that prepares a reduced randomised question bank from the 5MB file for every 24-hour period. Page visitors will then be randomly presented questions from the reduced text file.

I’m running with text files for now as I want to get this up and running quickly while I get my head round MySQL. Thanks for your explanations - they have been very helpful. Cheers.

Yes, you put my comments much more concise and verbal than I did…

But, you still missed the point a little. A simple site page like that can be done in MySQL in very little
code. It would be much much much faster and you can use command to randomly pick 5 questions
from your database in the one line query and no code at all is needed for the rest. No reading of any
text file, so no load on the server. MySQL systems are very fast these days, are secure and can pull
out random data using a LIMIT arg that means no coding to get your list of questions.

So, we all agree, take the time to read up on MySLQi commands and you can have this page working in
less than an hour!

Here’s a link to an excellent place to start: http://www.w3schools.com/php/php_ref_mysqli.asp
You will need to peek at how to open a database, how to execute a query and for the query check out
randomizing and LIMIT args. Simple to learn…

Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service