Jump to content

Limit file size (fwrite)


donatello

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.