3

I have php_mod and an apache server. If I start a script from the browser it will persist until the execution is complete ( even if i close the browser )

How can i stop the process ?

1
  • Sql execution or Php execution still continue ? Commented Oct 7, 2010 at 9:04

4 Answers 4

4

Normally, if you're sending output, this doesn't happen: if the webserver detects a disconnect, the PHP process is also stoppend (which is why we have functions like register_shutdown_function to make sure something is done (unelss you encounter a fatal error of course)).

However, as HTTP is stateless, the only point in time the webserver will detect a disconnect is when it is trying to send content (see also the remarks at ignore_user_abort (default is false, which is what you want)). Depending on the context of the request, a workable kludge could be in big loops to send non-displayed data to the user, in HTML that could be to send whitespace and flush. This can end up in any buffer though, (PHP's, servers, other places in the network) so detection is still not 100%, but that is about unavoidable. A sane time limit to avoid infinite looping, and only upping that limit for requests that actually need them is about the best you can do.

Sign up to request clarification or add additional context in comments.

2 Comments

are you sure that your answer is true for all the PHP environments. I am using PHP7.2 with apache2 on Ubuntu 18. But the php script continues to execute even after echo statement.
This answer from almost 10 years ago? Yes,especially if running as a module in Apache, the webserver will stop it when it detects there's no-one listening on the other end. Mind you, browsers keep open a lot mote connections in the background than they used to currently. The remark of 'all kinds of buffers' also applies, how much data are you sending? However, the long an the short of it is: don't run these long running jobs in a webserver, use queueing mechanisms somewhere (I used to use gearman, rabbitmq, kafka, but there are others, including a lot of Saas).
2

Check whether ignore_user_abort(true) is being set anywhere in the script. Or if there is a php_value ignore_user_abort directive set in .htaccess

Comments

-1

use in your script (if an amount of time has passed)

die();

Comments

-1

Closing the browser does not kill the running process. If you want to stop the background process, you will have to kill the process.

If you are using windows, you can restart apache using Apache service manager or kill it using Task Manager.

4 Comments

I would really appreciate if the downvoters would provide a little more information. Because I do run a lot of updation scripts. Maybe it is because I don't echo anything (all output is logged to files instead). The scripts run even if I close the browser, and I have to restart apache to make it stop. This is from my experience, and I do have a lot.
I didn't downvote but the information you want has been provided a long time ago with in the accepted answer ;-)
@Capsule I think the accepted answer is wrong. This answer is right. I am using ubuntu with php 7.2 and apache.
@AmarjitSingh it is right for Stack Overflow which is about programming. The question was actually not really programming related but more server related, so it should have been asked on Server Fault anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.