Log in

View Full Version : Server, let the user go!



Jas
03-13-2008, 06:44 PM
I have a php script that is suppose to run in the background of the server on a very very long loop. The problem is that a user has to call the script for it to begin. Is there a way to cut the users connection to the script? In other words:

<?php
ignore_user_abort(true);
set_time_limit(0);

header("Location: ./page.php"); //CUT THE USER'S CONNECTION HERE!

$x=0;
do{
$x++;
sleep(60);
}while($x<1000)
?>

Otherwise the user has to push the stop button or wait until the timer runs out. Right now the header does nothing until the loop ends-- and the loop doesn't end before the user times out.

Or perhaps there is a way to run the script in another way, such as via the system() function? (Again, though, it would need to be called through a php script and redirect the user rather then having them stick around until they time out.)

Jas
03-17-2008, 03:34 PM
Someone must have an idea. Don't be shy :)

NXArmada
03-17-2008, 03:37 PM
you can use a Crontab (http://en.wikipedia.org/wiki/Cron) for running the script

Running PHP Scripts with Cron (http://htmlcenter.com/blog/running-php-scripts-with-cron/)

Jas
03-17-2008, 04:12 PM
Thanks for the reply! A few questions:
1) Can I run that from a php script?
2) If so, how can I get the cron to run once (as opposed to every so often)?
3) What would it return?
I need to actually run the php loop as opposed to a cron, but if I can run the cron once to start the loop-- asuming that it will not keep the user around until the script finishes-- that would be great.

Jas
03-17-2008, 05:00 PM
I figured it out, and it seems to be working. Thanks!