Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using pdo, want to complete a 30 minute task

Posted on 2013-11-18
2
Medium Priority
?
294 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 35

Accepted Solution

by:
gr8gonzo earned 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The viewer will learn how to dynamically set the form action using jQuery.
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

783 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