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?
Can I Make A PHP Script Run FOREVER? OR Meta-Refresh maybe..
Moderator: General Moderators
-
superwormy
- Forum Commoner
- Posts: 67
- Joined: Fri Oct 04, 2002 9:25 am
- Location: CT
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()
Or perhaps you can attempt this method.
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(); ?>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