3

I have tried searching for this forever, but unfortunately I could not find the answer. I am calculating a whole lot of Pearson correlations on huge matrixes on my server. I do this by opening example.org/testscript.php.

The script itself will terminate about a 2 days after it has started and will perform many INSERT INTO databases for recommendation purposes.

I was wondering when I closed the window of my browser, whether the PHP script would stop or not. I am assuming not; however I am not a 100% sure.

P.S. I have noticed that in some browsers on some computers I will receive an internal server error (500) when starting the script after about 10 minutes. The script itself however was still running as it was still inserting rows in my database.

On this computer however I have not received such error and therefore I was wondering what would happen when I closed the tab.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 5
    2days? browser? do this in the background called from the cli –  Jan 08 '13 at 21:39
  • unfortunatelly, my hosting provider does not allow such options. – user1949616 Jan 08 '13 at 21:46
  • PHP normally has a max execution time, and it's normally set at around 30 seconds (not always, but it's a default in most builds). If you haven't altered the default PHP values your script should automatically stop after the [max_execution_time](http://php.net/manual/en/info.configuration.php#ini.max-execution-time) runs out? – Stu Jan 08 '13 at 21:48
  • Thanks for your reply. I have however set the max execution time to 0, which means infinity. I have done this on purpose. – user1949616 Jan 08 '13 at 21:49
  • im amazed any host, non dedicated, would allow anything to run so long. i very much doubt this would comply with their terms even if they are not currently stopping you, you should expect them to at some point in the future –  Jan 08 '13 at 21:54
  • Sounds like an educational environment, really doubt it is a paid shared hosting account. – donlaur Jan 08 '13 at 21:55
  • @user1949616 speaking as someone who worked in the IT dept for a shared hosting provider: your host hates you. They might not know for sure who is running a PHP script for days on end, likely reducing the performance to garbage, but they are likely not happy about it. You should be doing this on a dedicated machine where you *can* execute it from the command line and keep an eye on the process. – Sammitch Jan 08 '13 at 22:13
  • possible duplicate of [Can closing the browser terminate the PHP script on the server?](http://stackoverflow.com/questions/11360274/can-closing-the-browser-terminate-the-php-script-on-the-server) – Adam Friedman Apr 21 '15 at 02:45

1 Answers1

4

The php script will terminate after reaching the timeout. You can change the timeout: http://php.net/manual/en/function.set-time-limit.php

The browser will however timeout much sooner, if you are not producing any output. The browser timeout is of course browser-specific.

As Dagon suggested, the correct way would be to execute the php script on the server in the background.

Alen Oblak
  • 3,285
  • 13
  • 27
  • I wish the part about timeout was true, but it isn't. The [set_time_limit()](https://www.php.net/manual/en/function.set-time-limit.php) and the matching config directive `max_execution_time` measure CPU time, not elapsed time, so can't be used for this. To make matters even more confusing, if you run PHP on Windows, `set_time_limit()` works differently and measures actual elapsed time, so would work! – Brian C Jul 02 '20 at 01:11