Reputation: 396
When a browser send a http request to a web server. And that request will run a PHP script which will call function A, B and C.
If the browser's connection lost while the PHP executing function A, will it keep running the script and call function B and C?
Upvotes: 0
Views: 231
Reputation:
The problem is, that the traditional HTTP model is not an interactive model.
The only way to make definitely sure that your script doesn't run if the user has closed the page is:
1. Include these lines in the beginning of your script:
<?php
ob_implicit_flush();
ob_end_flush();
...
2. For code you don't want running after a user has quit:
<?php
if(!connection_aborted()){
//your code here
}
Hope this helps ...
Upvotes: 1
Reputation: 20747
With PHP this is simply controlled within the ini file:
; If enabled, the request will be allowed to complete even if the user aborts
; the request. Consider enabling it if executing long requests, which may end up
; being interrupted by the user or a browser timing out. PHP's default behavior
; is to disable this feature.
; http://php.net/ignore-user-abort
;ignore_user_abort = On
By default, in PHP 5.6.3, the behavior is to kill the script if you close your browser. Closing your tab, at least in Chrome, does not kill the script. You must close the browser.
Upvotes: 1