Solved

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

Posted on 2013-11-18
6
196 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 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 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
str_replace not working in php script 4 26
PHP: Query an Sqlite3 Datatbase return in JSON 6 48
mysqli insert query problems 4 22
Decrypt string by php 7 29
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 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