1

Recently i wrote an importing script in php, which will import some bulk data from remote server.

from browser i initiate the import operation and everything works good. but some time the remote server took some time to respond so i stopped the request using browser's "stop" button .

but it seems my apache is still processing the request.

So is there a way to stop the apache process when the corresponding request is stopped.?

2
  • Try to kill the process manually.... That could be a glitch so sometimes you needed to kill processes manually... How do you know that apache still retains the process even though you have stopped the process via browser.. Commented Jun 26, 2014 at 13:36
  • @LeoPrince - you do not stop the server-side process via the browser, so it's expected that it continues to run. And could you be more specific about how this "glitch" may occur? See my answer for an explanation of what's happening. Commented Jun 26, 2014 at 14:23

2 Answers 2

2

I don't think this is possible. When you press stop in the browser you just stop listening for/processing responses from the server. If the server is busy processing before it sends the response, you pressing stop doesn't send the server any more information, so it will continue to process until it finishes, then attempt to reply.

Remember that HTTP is stateless. You make a request, you wait for a response, that's all there is to it. In the behaviour you want, you'd need to make another request to the same process while the response is being processed/served, which doesn't follow the pattern.

The only way I think you could achieve this is by implementing another method that would take some parameters that could be used to locate and kill the long-running process. This would, of course, be a new, separate request.

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

1 Comment

got it, not possible through browser. Thanks for the explanation.
1

Try using ignore_user_abort() function in php.

Try this code

<?php
ignore_user_abort(false);
set_time_limit(0);

echo 'Testing connection handling in PHP';

while(1) {
    if(connection_status() != CONNECTION_NORMAL)  {
        break;
    }

    sleep(10);
}

?>

Fore more reference check this http://www.php.net/manual/en/function.ignore-user-abort.php

1 Comment

In my case I have the opposite problem, scripts are stopped when client is disconnected (browser stop / curl / wget stop etc). ignore_user_abort() doesn't seem to work on PHP 5, has no effect, none of the values

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.