PHP - Tweak code containing session and redirect

Viewed 39

I am having a LAMP Server on my Raspberry Pi. I have a static page to control my home switches. Also, I have a button which load the following php code.

PHP Code:

<?php
   # Session Close
   session_start();
   unset($_SESSION['valid']);
   unset($_SESSION['timeout']);
   
   # Server Shutdown
   system('sudo /sbin/shutdown -h now');
   
   # Redirect Page
   header("refresh:0.1;url=https://www.google.com");
?>
<!DOCTYPE html>
<html lang="en">
   <head>
   </head>
   <body>
      <!-- container -->
   </body>
</html>

The above code is doing: close session, shutdown server and redirect to a page.

This code seems to work fine but with delay... It takes time to load page. Press button and waiting...

I would like to ask if i can have the same result but faster. I need a tweak / speed up... Press button and instantly load redirect page and at the same time do the rest.

0 Answers
Related