• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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

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
rgb192
Asked:
rgb192
  • 3
  • 2
2 Solutions
 
Ray PaseurCommented:
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
 
Slick812Commented:
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
 
Ray PaseurCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rgb192Author Commented:
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
 
Ray PaseurCommented:
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
 
rgb192Author Commented:
thanks for advice about not using cookie

so I need ajax or db
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now