Pregunta

I was just wondering today whether or not the script terminated when the user exit the webpage (while loading). It turns out that yes, unless you set it otherwise. So, with that in mind, when does this script finish?

// Don't stop script even when the user closes the window
ignore_user_abort();

set_time_limit(0);

// Infinite loop (normally aborted when the user closes the window)
while(1) {
  sleep(1);
  }

My best bet is, when the PHP and/or the server is turned off/on. However, in a production system, this can be only in critical situations. So the question is, when would the script normally be ended? By normally I mean without any action being taken to end that specific script. Wouldn't the same script without the sleep() be a potential hazard for hosting companies? Set out one of them with a slightly expensive operation and the server is 100% for that script.

¿Fue útil?

Solución

Here is what I am thinking of:

  1. Apache restarted - Some hosting companies will do that if it reaches a CPU usage limit.
  2. Some hosting companies will limit your processes to x number of processes at the same time (ex: 1and1). So once three people access your site, everyone else will get error 500.

Some hosting also have ignore_user_abort/set_time_limit in their disabled_functions list for that same reason.

Update: Changed Many to Some. Guess the hosts I use are pretty different than what people normally use.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top