#1 - Are you sure it's not a PHP timeout?
Generally speaking, when a server is in SAFE MODE (which i know little about) there is a limit on the amount of time a script can run when executed by a user accessing the script in a web browser that cannot be changed within PHP at all. I have had some scripts that time out in a browser but I can easily run them from the command line when logged in as root.
If you are trying to run your script just for yourself, try running it from the command line. Login using SSH or something and try:
php -q my_long_script.php
If the script is timing out due to your browser's end and you are expecting to try and change everyone's browser timeout, I would discourage you from trying to change their browser's behavior. If you want this to work for the general case for people visiting with their browser, I would recommend trying to find another solution.
#2 - I have no experience writing shell scripts, but I found this linux one in phpGallery:
#!/bin/sh
# $Id: configure.sh,v 1.11 2004/06/09 21:48:15 cryptographite Exp $
chmod 755 setup
if [ ! -f config.php ]; then
touch config.php
fi
if [ ! -f .htaccess ]; then
touch .htaccess
fi
chmod 666 config.php .htaccess
echo ""
echo "You are now in setup mode. Your Gallery installation"
echo "can be configured by pointing your web browser"
echo "to the URL to 'setup' in this directory."
echo ""
I'm not certain, but I believe shell scripts are not subject to timeouts.
Here's an approach that could get your long query to run. If your PHP script runs from the command line, you might be able to get it to run by calling it using exec() to call the php file. If you manage to write a shell script that runs the query, you can exec that shell script instead.
You would need to create two extra php pages.
-- run_script.php --
<?
// this function would set some flag in a file or database to FALSE
// i leave it up to you to specify how this might be done
set_flag_to_false();
exec("php -q my_long_script.php")
or die("Script did not run!");
// if you had to use a shell script, you could change
// that line above to run your shell script:
//exec("long_query.sh")
// or die("shell script did not run");
header("location: wait_script.php");
?>
-- wait_script.php --
<?
// this function would check to see if the flag is true
// IMPORTANT: you will need to alter your long script to set the flag
// to TRUE when it finally finishes
// i leave it up to you to specify how this might be done
if (flag_is_true()) {
echo "QUERY IS FINALLY FINISHED! HOORAY!";
} else {
?>
<html>
<head>
<meta http-equiv="refresh" content="3;url='wait_script.php'">
</head>
<body>
WAITING FOR QUERY TO FINISH...
</body>
</html>
<?
}
?>
I'm not sure if all this is going to work....i'm really not good at the META tag stuff but I think that might work.