Home > Archive > PHP Language > April 2005 > infinite looping script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
infinite looping script
|
|
|
| I'd like to create a script that does some online processing for me, 24
hours a day, adding results to a database. It would essentially be a
worker thread. I'm not sure how to accomplish this with php.
something like this
for (;;)
{
// Get current temperature in Barrow, Alaska
// Get Current time/date
// Add these values to MySQL database
// sleep(60)
}
So if I load the page, this script will run but I need it to run forever.
| |
|
| On Mon, 25 Apr 2005 16:25:45 GMT, bruce@nospam.com (Bruce) wrote:
>I'd like to create a script that does some online processing for me, 24
>hours a day, adding results to a database. It would essentially be a
>worker thread. I'm not sure how to accomplish this with php.
>
>something like this
>
>for (;;)
>{
> // Get current temperature in Barrow, Alaska
> // Get Current time/date
> // Add these values to MySQL database
> // sleep(60)
>}
>
>So if I load the page, this script will run but I need it to run forever.
you can do it in a lot of ways, the first that comes to my mind is:
$forever=TRUE;
WHILE ($forever) {
your loop..
}
keep in mind that if your script is hosted somewhere like a public
hosting service (and / or a shared machine) they would possibly not
allow you to have an infinite loop and would break it automatically
after a certain amount of iterations. such processes are cpu-killing.
a similar, and a bit more fair, result could be accoplished putting
your script inside a auto-reloading page:
<meta http-equiv="refresh" content="10">
hope this helps
| |
|
| In alt.comp.lang.php
Gu <pistacchio@gmail.com> wrote:
>On Mon, 25 Apr 2005 16:25:45 GMT, bruce@nospam.com (Bruce) wrote:
>
>
>you can do it in a lot of ways, the first that comes to my mind is:
>
>$forever=TRUE;
>WHILE ($forever) {
> your loop..
>}
>
>keep in mind that if your script is hosted somewhere like a public
>hosting service (and / or a shared machine) they would possibly not
>allow you to have an infinite loop and would break it automatically
>after a certain amount of iterations. such processes are cpu-killing.
Ok, I understand they can be cpu killing, but that is the point of the
sleep(60), right? Its only going to run once a minute. I'm not going to
put up something that runs wide open all the time, never yielding.
>a similar, and a bit more fair, result could be accoplished putting
>your script inside a auto-reloading page:
>
><meta http-equiv="refresh" content="10">
Won't this only run when a page is displayed in a browser? I need a
background task constantly updating the database. It looks like the pctrl
functions would do it but my server does not have them installed. I'm
looking at popen() and procopen() but I don't think they'll do it. I wish
I could just spawn a worker thread.
| |
|
| On Mon, 25 Apr 2005 17:22:32 GMT, bruce@nospam.com (Bruce) wrote:
>Won't this only run when a page is displayed in a browser? I need a
>background task constantly updating the database. It looks like the pctrl
>functions would do it but my server does not have them installed. I'm
>looking at popen() and procopen() but I don't think they'll do it. I wish
>I could just spawn a worker thread.
hmm.. well, as far as i know whatever solution needs your webbrowser
open on the page of the script, as its execution is bound to the
session which starts when you open the page and ends when you close
it, close the browser or navigate elsewhere. if you can just launch a
script and have it run on the server just like a deamon would do..
well, if you find a hosting allowing you to do that, just tell me ;)
| |
| Kimmo Laine 2005-04-26, 3:56 am |
| "Bruce" <bruce@nospam.com> wrote in message
news:426d1889.1756245@news.dallas.sbcglobal.net...
> I'd like to create a script that does some online processing for me, 24
> hours a day, adding results to a database. It would essentially be a
> worker thread. I'm not sure how to accomplish this with php.
>
> something like this
>
> for (;;)
> {
> // Get current temperature in Barrow, Alaska
> // Get Current time/date
> // Add these values to MySQL database
> // sleep(60)
> }
>
> So if I load the page, this script will run but I need it to run forever.
PHP will timeout and halt infinite loops eventually ('execution time
exceeded' or something like that), but <?php set_time_limit(0); ?> will set
the execution time to infinite and you won't get the timeout.
--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com
| |
| Disco Octopus 2005-04-26, 8:57 am |
| Bruce wrote on 26/04/2005 :
> I'd like to create a script that does some online processing for me, 24
> hours a day, adding results to a database. It would essentially be a
> worker thread. I'm not sure how to accomplish this with php.
>
> something like this
>
> for (;;)
> {
> // Get current temperature in Barrow, Alaska
> // Get Current time/date
> // Add these values to MySQL database
> // sleep(60)
> }
>
> So if I load the page, this script will run but I need it to run forever.
Why dont you look into cron, and have a php-cgi script that will run
once each time the crontab tells it to.
Set your crontab to run the script every 10 minutes.
--
http://choicebeefjerky.com.au
food without company is medicinal
|
|
|
|
|