strago Posted February 18, 2010 Share Posted February 18, 2010 define("RANDOM_FILE","/public_html/random.txt"); $randomEntry = "This goes in text file.\n"; { $randomFile = fopen(RANDOM_FILE,"a"); } fwrite($randomFile,$randomEntry); fclose($randomFile); This adds text to a random.txt file. How do you make it also empty the file when there is over say 1,000 lines of data? Each line has 588 bytes of data, or 588K when it has 1,000 lines. How big does a text file need to be before it can slow the site down when the script looks for the random line? Quote Link to comment Share on other sites More sharing options...
alpine Posted February 19, 2010 Share Posted February 19, 2010 Something like this should work on resetting the file when reached 1000 lines <?php $lines = file('path/file.txt'); if(count($lines > 1000)){ file_put_contents('path/file.txt', $randomEntry); } else{ file_put_contents('path/file.txt', $randomEntry, FILE_APPEND); } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 19, 2010 Share Posted February 19, 2010 How big does a text file need to be before it can slow the site down when the script looks for the random line? That question is not what you meant to ask. Well, a 2kb file will take longer than a 1kb file, but you won't notice the difference. As to when you will notice a difference and, more importantly, when will that performance degredation be to a level that is unacceptable by you is impossible for anyone to determine via a forum. How bug the file will be before you start to have performance issues will depend on several factors: the efficiency of the code to extract the line, where the line of code is in the file, the specifications of the server(s) that the site is running on (CPU, memory, hard-drive speed/capacity), etc. Plus, if you are on a shared host, it will be even more difficult to determine the limits as you won't know what activity is going on for the other sites. The only way to detemine the limits is to run load/performance tests. Ideally, you would want exclusive access to the server. You would then run an application to simulate x number of users on the site performing various activities, where x is the max number of concurrent users you feel you need to support. Then you would increase the allowable size of the file at specific intervals and take recordings until performance degraded to a level that is unacceptable. Quote Link to comment Share on other sites More sharing options...
meltingpoint Posted February 19, 2010 Share Posted February 19, 2010 Like mjdamato said...it really is dependent on the code you are using to extract the info. At 588 bytes per line X 1,000 you have a file that is 588,000 bytes large or 574kb or .56Mb. I have heard that, with efficient coding, when you get to the 10 Mb size it can slow down the response noticeably. Just a ball park to work with in the event that you are not (as I am not) sophisticated enough to design and run the testing program the mjdamato was referring to. Cheers- Quote Link to comment Share on other sites More sharing options...
strago Posted February 21, 2010 Author Share Posted February 21, 2010 Thanks. Luckly I'm on a dedicated server so I won't have to worry about getting shut down if it get's too slow! <? $textfile ="random.txt"; $items = file("$textfile"); $item = rand(0, sizeof($items)-1); echo $items[$item]; ?> is the code. I think it looks through every line, THEN selects a random line!! Hence the file size worry!! Is it possible to make it any more efficient? Each line is <center><object width=500 height=400><param name=movie value=http://www.youtube.com/watch?v=$v&rel=0></param><param name=wmode value=transparent></param><embed src=http://www.youtube.com/watch?v=$v&rel=0 type=application/x-shockwave-flash wmode=transparent width=300 height=250></embed></object><BR><A HREF=http://www.tube-download.info/v/$v/>Download Video</a></form></center><HR> is there any way to make each line just be something like... XX1XX$vXX2XX$vXX3XX$vXX4XX and in the script do a search and replace to add the HTML? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.