0

Using a php to copy a dir and when finished to redirect browser ie
1. print "wait" message in browser.
2. copy the dir
3. finished copy redirect page
but noticed if dir is large (ie takes a long time) it is copied but the redirect does not happen, still see "wait" message. If time is few mins then seems to work but once higher eg 15mins (yes big dir) then see the problem.

<?php
set_time_limit(0); <<< otherwise PHP times out script execution
--do the dir copy---
echo "<script type='text/javascript'>
window.location.href='home.php';
</script>";
?>

If you replace the copy with a sleep() you also get a problem ie works for low values eg 5 secs but not higher ones eg 120sec.

Running on sun box with apache - tried increasing httpd "httpd.conf"
Timeout 300
(and restarted httpd) but made no difference
?>

4
Contributors
13
Replies
14
Views
6 Years
Discussion Span
Last Post by diafol
0

how about using a php refresh? Or even a redirect followed by an exit?

header( 'refresh: 5; url=somepage.php' );

I don't know whether this would make a difference. The refresh as I use it just gives my some time to flash a message prior to refresh.

0

Thanks for the reply but doesnt "header('refresh 5" mean do the redirect after 5 secs? I only want to redirect once the dir copy has completed.

Additional info - I added 2 additions to the top/bottom of my php file:
Top of script : print "start" + time to a log file
Bottom of script : print "end" + time to a log file
And both appear in logfile though browser has not redirected.

0

Yes I believe the refresh does. WHat about a simple php redirect?

header("location: ...");
exit;
0

"header" cannnot be used as the script has already output a "wait" message.
PHP manual "header": "must be called before any actual output is sent".

0

Also tried : echo "<meta http-equiv='Refresh' content='0; URL=home.php'>";
but behaviour is the same ie again only works if "delay" is not large

0

"header" cannnot be used as the script has already output a "wait" message.
PHP manual "header": "must be called before any actual output is sent".

If I recall correctly, using a buffer fixes the problem:

Example:

<?php 

ob_start('ob_gzhandler');
//dircopy
echo "whatever";
header("Refresh: 3; url=somefile.php");
ob_end_flush();

?>

The only problem I can think of is, it'll probably only echo once the dir copy is done :/
I hope this is useful

0

No ob_start will not work as it supresses the initial warning message telling the user to wait for the cp dir to finish ie script is:-
1. print "wait" message in browser to tell user the cp dir has started
2. do the cp dir
3. redirect page to "finished page" to tell user cp dir has finished

0

Its not just the redirect that fails - it seems javascript fails to work after a lengthy delay - an alert() also fails yet the later php file log write works. So its the browser not responding.

// not working
echo "<script type='text/javascript'>
alert('end');
window.location.href='home.php';
</script>";
// works
$time=date('G:i:s');
fwrite($LOG, "END TIME ===== $time\n");
fclose($LOG);
?>

0

pritaeas, I am using AJAX to call the php script but I can also put the PHP URL straight into the browser.

I've removed the javascript redirect and just tried using PHP to echo "FINISHED" at the end of the script but this also does not appear in the browser if a large delay occurs, Browser has status of "LOADING". It must be the apache server timing out but I tried increasing timeout (see above) and it made no difference.

0

Theres no soln to this - browser is timing out waiting for data from the server. I will have to not use the redirect and just stick with printing a message. Thank you for the suggestions.

0

If the execution time is ridiculous, how about breaking the task into bite-size ajax calls with a progress bar? You could have a recursive js function?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.