Solved

two tasks in same script: one task occurs once in around 30 minutes

Posted on 2013-11-18
6
203 Views
Last Modified: 2013-11-26
Looking for a code that allows me to do a small task
for example:
waiting
waiting
waiting
another 30 minutes have passed.
waiting
waiting
waiting
waiting
waiting
another 30 minutes have passed.

 

 I do not have access to a server that has a 30 minute timeout time.

So two tasks can be done with this one script.  I do not want 2 cron jobs to run 2 scripts.
echo
waiting

or

echo
another 30 minutes have passed.

Note: does not have to be exactly 30 minutes.


Allowed to use a cookie and pdo to access mysql.
0
Comment
Question by:rgb192
  • 3
  • 2
6 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39656682
What are these tasks supposed to do?  What is the advantage you want to get by waiting?

You may be able to use some combination of set_time_limit() and sleep(), but bear in mind that server output buffering may prevent you from seeing any browser output until the script ends.  It may be difficult to monitor the progress of the script.
0
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 250 total points
ID: 39657454
greetings  rgb192, , a PHP server and the PHP page code and display, were NOT meant to do anything like this at all, PHP and all other server side code platforms (JSP, ASP) are made to deliver a web page from dynamic database reads  AS FAST AS POSSIBLE! !, and not be waiting around for even one minute, much less an hour as you have outlined above. It may be possible to just have the PHP code do delays with sleep, but there are many problems in PHP that you may not be able to over write to get this to work. My opinion is you really need to have another different idea-method to do your page output every 30 minutes.
I would change to a browser based javascript AJAX method, that would do an AJAX return from PHP every 30 minutes. This is what the AJAX was made to do, ,  and there may be no Problems in javascript code that you need any special code over-writes, to get this to work with AJAX.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39657546
So two tasks can be done with this one script.  I do not want 2 cron jobs to run 2 scripts.
Why not just use one CRON job?  It can start one script that does two different tasks.  Here is an example of how that might work.

<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);

function longsleep($minutes=1)
{
    while ($minutes)
    {
        sleep(20);
        sleep(20);
        sleep(20);
        $minutes--;
    }
}

// PERFORM TASK #1
echo '<br>' . date('c');

// WAIT A WHILE
longsleep(2);

// PERFORM TASK #2
echo '<br>' . date('r');

// WAIT A WHILE LONGER
longsleep();

// PERFORM TASK #3
echo '<br>' . date('H:i:s');

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rgb192
ID: 39673599
Could I save information to a cookie or database and have the cron job run every minute

if cookie value=30 or database increment value=3- then do something
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39674765
To a database, yes.  But probably not a cookie.  A cookie is part of the HTTP request, and I think that CRON jobs are not started via HTTP requests (at least not the kind that can send cookies).
0
 

Author Closing Comment

by:rgb192
ID: 39679249
thanks for advice about not using cookie

so I need ajax or db
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

Suggested Solutions

Title # Comments Views Activity
I've got an interview this morning and I want to sound intelligent... 4 69
Cpanel file manager 8 41
how to use a switch statement with heredoc 11 33
jQuery force form POST 7 45
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

856 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