Can I Make A PHP Script Run FOREVER? OR Meta-Refresh maybe..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Can I Make A PHP Script Run FOREVER? OR Meta-Refresh maybe..

Post by superwormy »

I have a PHP script that I want to run FOREVER. IE, never end, either that OR I want it to refresh after it runs each time.

My original thought was to set an HTML meta-refresh tag, HOWEVER, I'd like to run this on Unix using Lynx, but Lynx does not follow meta-refresh tags ( does anyone know how to make it follow meta-refresh? )

It's been suggested I use Cron to schedule it, but theres no way to know how long the script will take to run, ie sometimes it takes 20 seconds, sometimes it takes 2 seconds.

It just runs queries on a database, and I'd like to have it run for MONTHS at a time, does nayone have any ideas? Can I turn off the script execution time limit? Will PHP / Apache crash if I do this and let it run for 3 months at a time?
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

Personally I would schedule a Cron job for this, however you can use the header() function to refresh/redirect the page and the sleep() function to delay the script. To be sure that you aren't sending anything to the browser prior to the header() command use output buffering with ob_start() and ob_end_flush() -- although ob_end_flush() isn't needed in MOST cases because it is called automatically at the end of script execution by PHP itself when output buffering is turned on either in the php.ini or by calling ob_start()

Code: Select all

<?php ob_start(); ?>

<?php 
// your page, script, or code here
sleep( '5' );
header("Location: http://$SERVER_NAME/page.php"); ?> 

<?php ob_end_flush(); ?>
Or perhaps you can attempt this method.

Code: Select all

<?php ob_start(); ?>

<?php 
// your page, script, or code here
header("refresh: 5; url=http://$SERVER_NAME/page.php"); ?>

<?php ob_end_flush(); ?>
Last edited by Kriek on Thu Jan 30, 2003 8:48 am, edited 2 times in total.
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Post by superwormy »

Hey... ya know... that just might work... damn...

Thats a good idea, thanks :-)
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

If you don't need the result over http you could just run it on the server as a 'daemon' using the php-cgi executable? Just make a never ending loop with a sleep() inside..
Post Reply