If an ajax request is made to server to run a script in backend and user closed the browser. Will that script complete execution on backend if it started and was in midprocess?
NO.., PHP script will not terminate its execution.
YES.. it'll complete its execution.
Once php script is initiated, it'll complete its execution and then will stop.
because, php runs at server side, it can't be interrupted by client side simple event like browser window close
.
But however client will not be able to see the output.
for ex:
Try This Code:
//File Name: xyz.php
<?php
$fp=fopen("output.txt","w");
$count=0;
for($count=0;1;$count++){
//Infinite loop
fwrite($fp,"".PHP_EOL."".$count."");
sleep(1);
if ($count>=60) break;
}
fclose($fp);
?>
and now test this file, Even after you close the browser window, it'll continue to print inside that output file (output.txt
).
Well, PHP is server side, it computes all the code and then sends the results to the client. So I guess it finishes the script execution even if you close the browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With