Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using pdo, want to complete a 30 minute task

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

722 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