Solved

using pdo, want to complete a 30 minute task

Posted on 2013-11-18
2
285 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This article discusses four methods for overlaying images in a container on a web page
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 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