Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Is $expire a global value?

Posted on 2005-05-16
3
Medium Priority
?
194 Views
Last Modified: 2011-09-20
Hello,

I have no PHP experience, but am familiar with perl and some other languages.  I'm using a PHP script from the Open Source community.  It is a front end to a MySQL database.

One of the functions selects distinct hosts from the database.  It then populates the webpage, but also writes them to a text file. Then on subsequent calls, it checks that text file, and if it exists, and is recent, is uses that list to populate the web form, instead of doing the SQL Select (to save overhead).

Nice idea.

But I'm jsut trying to understand when it decides to use the text file.  The code says:

      if (file_exists($file) && filemtime($file) > (time() - $expire))

Can someone explain that line to me.  It's checking the date stamp of the file, and comparing it to the current time minux $expire.  I can't find $expire defined anywhere.  Is that a global PHP thing?

0
Comment
Question by:shanepresley
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Promethyl earned 2000 total points
ID: 14012798
If the text file holding our cached data exists and the time the file was last modified is greater than the time on the server minute the time to allow the textfile to live then refresh the text file.

I would do :
       echo "The cached data lives for : ". $expire . ' time units.<br>';
      if (file_exists($file) && filemtime($file) > (time() - $expire)) {  }

Check that and see. Most likely it's defined in another file. Search for expire. It's either in there, or the programmer mistakenly left it out.


0
 
LVL 1

Author Comment

by:shanepresley
ID: 14012953
Correct!! Thank you.  It was defined in another file (an include)

common_inc.php:$expire          = 86400 ;       // Cache life of one day.

So if the file exists, and is newer than one day..use the cache.

Works for me!

0
 
LVL 7

Expert Comment

by:Promethyl
ID: 14013305
You can actually tune this to your needs... More or less time as necessary. If your data only changes once a week, set it to a week, and then do manual refreshes as necessary.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question