Solved

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

Posted on 2013-11-18
6
188 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

13 Experts available now in Live!

Get 1:1 Help Now