Solved

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

Posted on 2013-11-18
6
191 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 108

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 33

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 108

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now