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
https://forums.phpfreaks.com/topic/225074-limit-file-size-fwrite/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.