Solved

using pdo, want to complete a 30 minute task

Posted on 2013-11-18
2
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
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…
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.

759 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