Solved

using pdo, want to complete a 30 minute task

Posted on 2013-11-18
2
279 Views
Last Modified: 2013-11-18
Looking for a code that allows me to do a small task (for example echo 'hello') every 30 minutes.  I do not have access to a server that has a 30 minute timeout time.

Allowed to use a cookie and pdo to access mysql.
0
Comment
Question by:rgb192
2 Comments
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 39656492
I don't understand the question. There are three possibilities that come to mind (just given your history of questions):

1. Cron job - Use a cron job (or Windows scheduler) to run a PHP script every 30 minutes.
*/30 * * * * /path/to/php/script

Open in new window


2. Long-running PHP script - Have a PHP script that runs in an infinite loop and echoes "hello" every 30 minutes:
<?php
set_time_limit(0);
$thirtyMinutes = 60 * 30;
$startTime = time();
while(true)
{
  $elapsedTime = $startTime - time();
  if(($elapsedTime > 0) && (($elapsedTime % $thirtyMinutes) == 0))
  {
     echo "hello";
  }

  sleep(1);
}

Open in new window


NOTE: If your server uses gzip compression or output buffering of any kind, this won't work if you try to view it as a web page, because the script never ends, and compression/buffering requires the output to finish before anything is displayed, so you would just see a blank page that never finished loading.

3. Long-running Javascript - Use window.setInterval to do the task every 30 minutes:
var thirtyMinutes = 1000 * 60 * 30;
setInterval(function(){alert("Hello")},thirtyMinutes);

Open in new window


NOTE: Since you asked this in the PHP forum, I'm doubtful that Javascript is what you want, but I proposed it because you -COULD- use Javascript to call a PHP script via AJAX.

There are caveats with each solution, but what confuses me is that you were talking about a server "timeout time" and cookies and PDO, but that has nothing to do with a scheduled task...
0
 

Author Closing Comment

by:rgb192
ID: 39656614
thanks.
You have answered that question allowing me to think of another as you help me with the requirement.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28297067.html
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now