PHP / Linux / WebBrowser Question - never-ending PHP script...?

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
I want a PHP script to run forever and ever and ever, ie never ever stop running.

I know if it was a Windows box I could just set a <meta name="refresh" content="0"> tag and let IE keep auto-refreshing. But I'm using Linux. And I'd rather not have to have XFree86 running all the time ( resource hog ), and for some reason, Lynx doesn't obey meta refresh tags.

So how can I make the PHP script never end? Or auto-refresh?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
This, or it's syntactical equivelent, will work in almost any programming language:

while(1){
}
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
I could use the while trick, but PHP has a time limit placed on scripts, it dies after the script runs for a certain number of seconds, hence the meta-refresh trick.

Does anyone know if I can turn off that time limit in PHP? Or better yet, force Lynx to follow the Meta-Refresh tag?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Superwormy
I could use the while trick, but PHP has a time limit placed on scripts, it dies after the script runs for a certain number of seconds, hence the meta-refresh trick.

Does anyone know if I can turn off that time limit in PHP? Or better yet, force Lynx to follow the Meta-Refresh tag?

I'm confused as to what you're trying to do. Do you want this script to display on a webpage, or do you just want some process to be constantly running?

Refreshing overy 0 seconds will not keep your process running, it will complete, write "refresh" to the web browser, the browser will request the page again, and the script will run through another time.
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
I just want a single script to either execute continuously for months on end, or a single script to execute over and over again for months on end.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Superwormy
I just want a single script to either execute continuously for months on end, or a single script to execute over and over again for months on end.

What is it that this script is supposed to do?
 

Need4Speed

Diamond Member
Dec 27, 1999
5,383
0
0
Originally posted by: notfred
Originally posted by: Superwormy
I just want a single script to either execute continuously for months on end, or a single script to execute over and over again for months on end.

What is it that this script is supposed to do?

yes...thats what i said i wanted to know as well
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
I did something similar, but with a different method.

I put a "wget -q -0 /tmp/tmpfile http://myserver/myphpfile.php" in the crontab...

Works like a charm. PHP script is run whenever I need to (well, if you don't need it more often than the time resolution of cron)
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
The script runs queries on the database to sort text. It needs to run as much as possible.

Now does anyone actually have a solution???
 

kt

Diamond Member
Apr 1, 2000
6,028
1,342
136
Originally posted by: Superwormy
The script runs queries on the database to sort text. It needs to run as much as possible.

Now does anyone actually have a solution???

A better question is why you need to run a PHP script to do that? Like someone already suggested, use cron process to accomplish what you need.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
You don't even need cron (cron would fork a new process for each invocation which could get ugly), just write a small wrapper in perl, C or anything that does:

while (1) {
run_script();
sleep(5);
}
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
You could do that 1000 times more efficiently if you jsut sorted stuff whenever you performed an insert.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
not that i'm condoning whatever method you are using, but to disable PHP's max execution time you would use set_time_limit(0)
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
You people are absolutely ridiculous! ALL I WANTED WAS AN ANSWER, WHY DOES EVERYONE NEED TO KNOW WHAT I'M DOING WITH IT / EXPLAIN HOW THEY DON'T 'CONDONE' WHAT I'M DOING?

Oh, and notfred, you don't understand what I'm doing, sorting on the Insert WILL NOT be faster, the data is already there.


Thank you BingBongWongFooey for letting me know how to disable that. In addition to that, I'd like to know if there is a way to have Lynx follow the Meta-Refresh tag. Does anyone know???

Also thank you to the people who suggested Cron, HOWEVER, one problem with that is there's no way to determine how long the script will take to execute, sometimes it might take 30 seconds, sometimes only 3 or 4 seconds. So I'd really rather have the script run again whenever the first one finishes... not sure if theres a way to accomplish that.

Anyone else?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
You people are absolutely ridiculous! ALL I WANTED WAS AN ANSWER, WHY DOES EVERYONE NEED TO KNOW WHAT I'M DOING WITH IT / EXPLAIN HOW THEY DON'T 'CONDONE' WHAT I'M DOING?

Because the way you're going about it seems, well, wrong. But we can't speculate on suggesting a better solution until we know the problem. Usually people are happy to find out there's a better way to do things.

Also thank you to the people who suggested Cron, HOWEVER, one problem with that is there's no way to determine how long the script will take to execute, sometimes it might take 30 seconds, sometimes only 3 or 4 seconds. So I'd really rather have the script run again whenever the first one finishes... not sure if theres a way to accomplish that.

The while wrapper script would work, depending on how you call the thing you can have the wrapper block on it's execution so there's won't be any concurrent runs.
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
Because the way you're going about it seems, well, wrong. But we can't speculate on suggesting a better solution until we know the problem. Usually people are happy to find out there's a better way to do things.

The while wrapper script would work, depending on how you call the thing you can have the wrapper block on it's execution so there's won't be any concurrent runs.


First off, can anyone help me get started on a wrapper which blocks it's exectution so there won't be concurrent runs? Just would like to know what language would be the best / quickest to write this in, how I would check to see if it's already being executed, thanks!

Also, what in the world seems so wrong about doing it this way? Unfortunately, the script is written in PHP, and I dont have time to re-write it in another language. I need the script to run as much as possible, continuously running queries on a database and sorting text for weeks if not months on end. Thank you to anyone who actually helped, and thanks Nothinman for the idea of being able to check if the script is already running, so theres no concurrent runs, any idea how I might implement that, or can you give me some hints as to what language is best to do that in / a tutorial for a start point ... anything?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Doesn't php come with a command line interpreter? I havn't really messed with it, but I thought I saw one.

#!/usr/bin/perl

while (1) {
system("command line to run"); #any command can be executed here just like if you typed it from bash
sleep(1); # pause for 1 second between runs, optional since perl blocks on system() anyway.
}
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
Edit: Nothinman, actually your solution would work. In the system call, one would just put the wget command line I mentioned further up.

--------------------

PHP only comes with a command line tool in the newer versions (4.3+)... It's not 100% stable yet.

The advantage of a cron script is that you can also run an external script that:

a) puts up a lock
b) does the wget
c) removes the lock

That way you never have to php scripts running at the same time. Without PHP 4.3+ and a command line tool, that's pretty much the only solution short of modifying the source of wget... (Or some similar program)

 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
Originally posted by: RSMemphis
PHP only comes with a command line tool in the newer versions (4.3+)... It's not 100% stable yet.

The advantage of a cron script is that you can also run an external script that:

a) puts up a lock
b) does the wget
c) removes the lock

That way you never have to php scripts running at the same time. Without PHP 4.3+ and a command line tool, that's pretty much the only solution short of modifying the source of wget... (Or some similar program)

Can someone explain to me what is meant by ' putting up a lock ' and how to do it? Thanks guys!
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
The advantage of a cron script is that you can also run an external script that:

a) puts up a lock
b) does the wget
c) removes the lock

That way you never have to php scripts running at the same time. Without PHP 4.3+ and a command line tool, that's pretty much the only solution short of modifying the source of wget... (Or some similar program)

Actually I think that would be a more convoluted solution. Because now you have to have logic to deal with the locking, and if you just spin on the lock you can have a big backlog of processes waiting to run, so instead of 4 processes trying to run at once you have 1 running and who knows how many (if it starts backing up, chances are it'll only get worse and the line will get longer) sleeping and waiting to run.

You're right about wget though, I forgot about that. In the perl script I posted just put "wget -q -O /dev/null http://url" in the system() command and it'll probably do exactly what you want. "-q" tells wget to be quiet and not print anything to the console and "-O /dev/null" tells it to write the file to /dev/null so you don't have to delete any files, this is assuming you don't want the output saved anywhere.