Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 992241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:14:04+00:00 2026-05-16T06:14:04+00:00

HI, My php is very rusty and I can’t quite remember how to do

  • 0

HI, My php is very rusty and I can’t quite remember how to do this.

I have a script that i only want to call every 15 minutes. I’ve created a table called last_updated. What I want to do is have some code at the top of my script that queries this last_updated table and if now() minus the last updated is greater than 15 minutes then run the script and also update last_updated to now…if it isn’t don’t run the script. Does this make sense?

Now I know when I’m updating last_updated I need to use now() To put a new timestamp in but I;m not sure how to do the comparing of now with the db value to see if it’s greater then 15 mins.

Any ideas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:14:04+00:00Added an answer on May 16, 2026 at 6:14 am
    <?php
    $pdo = new PDO('mysql:host=your_host;dbname=your_database', $user, $password, array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
    
    // query the database. change 
    $stmt = $pdo->query('SELECT UNIX_TIMESTAMP(last_updated_date) FROM last_updated ORDER BY last_updated_date DESC LIMIT 1');
    
    $lastUpdatedTimestamp = $stmt->fetch(PDO::FETCH_COLUMN);
    
    if ((time() - $lastUpdatedTimestamp) > (60 * 15)) {
        touch($file);
        // do stuff
    }
    

    time() gives you the current time in seconds. You should probably unroll 60 * 15 to 900, I just provided it with both numbers to illustrate what was going on.

    Also, a file might be better for this than a database table. Have a look at the touch()
    function. It changes the modification time of a file, or creates an empty file with the current time as the mod time if it doesn’t exist. You can check the file mod time with filemtime()

    <?php
    $lastUpdated = null;
    $file = '/path/to/writable/file/with/nothing/in/it';
    
    if (file_exists($file)) {
        $lastUpdated = filemtime($lastUpdated);
    }
    
    if (!$lastUpdated || (time() - $lastUpdated) > 900) {
        touch($file);
        // do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a very busy PHP script we have a call at the beginning to
i have this very simple php script: <?php require 'functions.php'; $token = some-number; $id
My PHP is very rusty. I have a md5 hash that's being passed via
I am creating a very large PHP MVC-based site that will have a large
I remember coming across a very minimalistic PHP CMS that targets mainly artists as
I have a very large php maintenance script (basically it recreates thumbnails for an
In PHP I can access class attributes like this: <?php // very simple :)
I'm trying to create a very simple PHP CLI application that can be run
This is probably v.easy but my php is very rusty. I need to implement
Just say I have a file configuration.xml that a php script needs to parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.