Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Bruce
04-25-05 08:56 PM


Re: infinite looping script
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


Report this thread to moderator Post Follow-up to this message
Old Post
Gu
04-25-05 08:56 PM


Re: infinite looping script
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Bruce
04-25-05 08:56 PM


Re: infinite looping script
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 ;)

Report this thread to moderator Post Follow-up to this message
Old Post
Gu
04-26-05 01:55 AM


Re: infinite looping script
"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



Report this thread to moderator Post Follow-up to this message
Old Post
Kimmo Laine
04-26-05 08:56 AM


Re: infinite looping script
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


Report this thread to moderator Post Follow-up to this message
Old Post
Disco Octopus
04-26-05 01:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:28 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.