0

I have a really long php script (up to 4 hours) and the script part works fine. it runs the entire 4h. doesnt timeout But i want the result in my browser, and on the browser side, after +- 35-40min the browser stops loading (firefox) and just returns an empty page.

I know there are probably a dozen ways to get the result to me, without having the browser open. But i am not looking for that.

I really have no idea where to start with troubleshooting this issue. Like, is this a browser or a server issue? things to note:

  1. The php script does not stop when the browser returns an empty screen (no error message, and the script itself keeps running)
  2. If i split the script and make it refresh the browser window after 10min, it still returns an empty page after +-40min
  3. if i run 2 scripts, they stop at the same time
  4. no error messages on my servers side
  5. the same issue happens if i simply have a script with sleep(4800); in it

the php script starts with:

set_time_limit(0);
ini_set('max_execution_time', '0');

in htaccess i have:

RewriteRule (myfile)\.php - [E=noconntimeout:1]
RewriteRule (myfile)\.php - [E=noabort:1]

in php.ini i have execution time to -1 and 4096m memory etc.

tldr: browser sort of times out (no error, but returns empty screen) while script goes on. how do i prevent this, or what area should i look to find the issue?

edit: if i build in a loop, and split the sleep(4800); example to: sleep(1200); then with javascript reload the page (4 times total). i still get the same issue

<script type="text/javascript">
var php_varurl = "<?php echo myurl; ?>";
newwindow=window.open(php_varurl, '_self');
</script>
Phpnewb
  • 127
  • 1
  • 9
  • 2
    Instead of waiting for 4 hours on a page load, maybe have the page occasionally poll the server for results via AJAX? Or keep a web socket open in the JavaScript? A 4-hour page load time is... not awesome. But a user can sit on an already loaded page which has background logic that continues to communicate with the server. – David Jan 06 '21 at 14:03
  • Does this help answer your question: [Connection timeout in firefox](https://stackoverflow.com/a/24983902/5946202) ? The problem is we will only know in 40 minutes. – Abbas Akhundov Jan 06 '21 at 14:21
  • i have just edited that, it was only at 90 seconds so perhaps that wasnt it (but we will find out in 40min :P) (this is also why troubleshooting it has been such a pain) @David the script is only for personal use, so i would really like it in the browser. (it should be possible, i have done this before, my gut feeling says its something on the server side) – Phpnewb Jan 06 '21 at 14:27
  • @Phpnewb: *"so i would really like it in the browser"* - Which is exactly what AJAX and/or Web Sockets provides. There's a certain simplicity to waiting on a page load, but overall the architecture really isn't designed for that and the struggle you're currently facing is evidence of that. But looking to things like the message notification in the header here on Stack Overflow or other similar functionality on other popular sites (pretty much any social network for example), we find examples of doing this as a background task in the browser for a tab that's open for hours/days/weeks/etc. – David Jan 06 '21 at 14:31
  • fair enough. i guess the main issue with that would be i have 0 experience with that. and no idea how to start even XD – Phpnewb Jan 06 '21 at 14:41
  • @Phpnewb: Also fair. If you're up for it then this is a great opportunity to learn the technologies involved. A quick Google search for "php websockets" finds many results, and there are a variety of tutorials to get you started. The usual example for a "websockets hello world" is a simple chat application. But the general architecture is widely applicable. The basic premise is that the page is already loaded and some JavaScript listens in the background for messages from the server. The PHP code can then send those messages (any data you like) at some later time. – David Jan 06 '21 at 14:46
  • @David it does sound what i am looking for. The learning will have to wait a bit till i have some more free time. but will look at it for sure. didnt even know this was a thing – Phpnewb Jan 06 '21 at 14:57

0 Answers0