Hello Which one process faster and takes low cpu load to complete the job. job: lots of image links to be displayed on a page. 1st way) write all the links in a text file per line .. and loop through that text file. 2nd way) make a mysql table which will contain the text links.. i want to know if the sites gets heavy traffic which one of these two method will be beneficial with respect to speed and load on server. Thanks.
The mysql db will be a hell of a lot easier to maintain and probably a little faster than the text file.
this will depend a lot on the implementation of how you read a file - if you read the whole file in memory and then read each line, I guess it's a bit quicker then mysql as you have less overhead if you do a read access to disk for each next line it will be a lot slower..
definately reading a text file will be more fast and plus it wont put a load on ur server. Regards Alex
The answers here don't really suffice. There are 2 possibilities. 1. Server has a lot of requests... 2. Server is slow and site is small In instance 1 you want mysql or another database. For instance 2 you can use a filesystem just fine. Keep in mind databases are in general a lot easier to deal with large selection of information. That's their purpose.
Maybe there are the third solution, take these links as a variable, and serialize it into file systems. e.g. in php: The file contains: And in the script:
The whole point of developing databases was for their speed. If the text file is very small - I can't give an exact number, perhaps bellow 1000 lines - then text file is faster otherwise you should definitly go with database. The surrest bet: put a php timer on your page and try both ways.
Thanks to all for this quality information. mahmood has suggested a good idea of checking by a timer .. its just like a gallery !! say i have server 1 -> contains script which displays the image on a page. server 2 -> contains images. now i have to store all the image(server 2) links on server 1 in a text file or in a database.. But now i guess i have to go with database only becoz one thing i havnt thought before .. was that the images r in catagories.. so there must a search condition to pick up images from categories... database goes easy on this.. rectangleman's suggestion is also good .. as yes the server will get lots of request .. Thanks to all others for their suggestions.. now i need to work my brain out for this job ..
for normal access , Text will be faster , fot searching also text faster , but when you have large Text file or long text you have to build your own algorithm to maintain fast searching , otherwise any database has indexing service will be much faster .
one think more , building Search engine not easy with Text file , because you have to know every data place accoiding to another ( Postition )
Third way - reading the entire text file at once (not reading a line at a time). Which is faster? Reading the whole text file at once. Which uses less CPU? That depends on the database. Which is easier to write, easier to maintain and better? A database.
If you are using proper query than mysql is little faster compare to the plain text file as text file will read data sequencially
processing a mysql db is faster than reading a text file because text editor are not generic to which will be there in it or text file can have error . So processing a sqldb is faster.this also depends upon the hosting server you are using for your website