-4

I need to increase the session time from 20 minutes to 2 hours on the Azure platform.

karel
  • 5,489
  • 46
  • 45
  • 50
Fábio Zangirolami
  • 1,856
  • 4
  • 18
  • 33

3 Answers3

1

I searched for changing session timeout in web.config file of IIS configuration, but there are not any seesion configuration related to PHP or other languages, except ASP and IIS self, as the figure below.

enter image description here

So you don't worry about there are other options outside PHP which will impact PHP session timeout, just to change PHP configuration.

There are many ways to change session timeout in PHP.

  1. Change session timeout in php.ini or via the related API.

    Set session timeout in php.ini

    session.cookie_lifetime = 7200 // 2*60*60 seconds
    session.gc_maxlifetime = 7200 
    

    Or using ini_set function in PHP code.

    ini_set('session.gc_maxlifetime', "7200"); 
    ini_set("session.cookie_lifetime","7200"); 
    
  2. To store the last time of the user request via set a timeout property in $_SESSION, and check how long ago with the next request, please refer to the existing SO thread PHP Session timeout.

    <?php
      // set the last time for each request as previous time
      $_SESSION['timeout'] = time();
    ?>
    
    <?php
      // check the interval time with the previous request time in the current request
      if ($_SESSION['timeout'] + 10 * 60 < time()) {
         // session timed out
      } else {
         // session ok
      }
    ?>
    

You can search in StackOverflow or Search Engine like Google or Bing to find other solutions, such as this SO thread How to change the session timeout in PHP? .

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
1

Adding to Peter's response. Azure Load Balancer has a default idle timeout setting of approximately four minutes (230 sec. It is the maximum amount of time that a request can take without sending any data back to the response If your web app requires background processing you could leverage recommend using Azure WebJobs or Azure Functions is another option.

If sending data back to keep it alive is not feasible, the suggested approach is to move to an async pattern. Additionally, by default, when your build process launches some command, it's allowed to run for up to 60 seconds without producing any output. If that is not long enough, you can make it longer, e.g. to make it 10 minutes: SCM_COMMAND_IDLE_TIMEOUT=600

Refer the following documents for more details on this topic:

https://learn.microsoft.com/en-us/azure/app-service/faq-availability-performance-application-issues

https://social.msdn.microsoft.com/Forums/en-US/05f254a6-9b34-4eb2-a5f7-2a82fb40135f/time-out-after-230-seconds?forum=windowsazurewebsitespreview

AjayKumar
  • 2,812
  • 1
  • 9
  • 28
0

Thanks for the attention @ajaykumar-msft and @peter-pan. I solved the problem of creating an applicationhost.xdt file and downloading the original .ini file from theloader configuration file directory in phpinfo I copied it to thesite folder I edited and changed from session.gc_maxlifetime = 1440 to session.gc_maxlifetime = 7200. Happy =)enter image description here

my file applicationhost.xdt:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.webServer>
        <fastCgi>
            <application>
                <environmentVariables>
                    <environmentVariable name="PHPRC" xdt:Locator="Match(name)" value="d:\home\site\php7.2.10.ini" xdt:Transform="SetAttributes(value)" />
                </environmentVariables>
            </application>
        </fastCgi>
    </system.webServer>
</configuration>
Fábio Zangirolami
  • 1,856
  • 4
  • 18
  • 33