donatello Posted January 20, 2011 Share Posted January 20, 2011 I have a simple script which records search terms and writes them to an external file. I would like to limit this file size. The Use: I have a search page where people can search for PDF files. I would like to have a 'cloud tag' or list of the most recent terms searched at the bottom of the page. Here is my script which works beautifully: <?php $pattern = "/filetype:(\w+)/"; // filteype:(wildcard for word) to grab the file extension along with the word filetype: if ( $_GET['q'] == "" ) { $term = ""; } else { $term = preg_replace("$pattern", '', $_GET['q']); // get rid of the filetype parameter } $searched = $term . ", "; $fopen = fopen("searched.html", "a"); fwrite($fopen, $searched); fclose($fopen); ?> The above code grabs the search term when the SERP page is opened, and writes it to a file. I will later use phpInclude to put the contents of that file on the bottom of my search engine page. The problem is that after a million searches, this file will be huge! Question: How can I limit the file size and organize these search terms so that the most recent ones appear on the page? Quote Link to comment https://forums.phpfreaks.com/topic/225074-limit-file-size-fwrite/ Share on other sites More sharing options...
litebearer Posted January 20, 2011 Share Posted January 20, 2011 It might prove easier to use a db table with a datetime field. when retrieving from the table ORDER BY the datetime field DESCENDING. AND Deleteing all records older than a certain datetime would be a breeze Quote Link to comment https://forums.phpfreaks.com/topic/225074-limit-file-size-fwrite/#findComment-1162513 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.