0

I need that both iframes forms work independent (async) but when i submit both forms at the same time the second iframe report "Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\iframe2.php on line 2" (when the iframe1 query is a long process) or the second iframe return data AFTER the first process is complete (when the iframe1 query is a short process). Now, i need keep the session for validate user login. i need your help, my friends! thanks

index.php

<html>
<head>
<title></title>
</head>
<body>
<iframe src="iframe1.php" width="300" height="400"></iframe>
<iframe src="iframe2.php" width="300" height="400"></iframe>
</body>
</html>

iframe1.php (return query results)

<?php
session_start();

if($_SESSION['user'])
  $data="Valid user";
else
  header("location: login.php");

set_time_limit(120);
require_once("config.php"); //db conections
if($_POST)
{
  //query (long process)
  $data.= ""; // concatenated string with query results
}

?>
<html>
<head>
<title></title>
</head>
<body>
<?php echo session_id();?>
<form method="post">
ini:<input type="text" name="var1" value="" /><br />
fin:<input type="text" name="var2" value="" /><br />
<input type="submit" value="Send" />
</form>
Result:<br />
<?php
if(isset($data))
  echo session_id()."<hr>".$data;
?>
</body>
</html>

iframe2.php (only return 123456)

<?php 
session_start();

if($_SESSION['user'])
  $data="Valid user";
else
  header("location: login.php");

if($_POST)
{
  $data =  "123456";
}
?>
<html>
<head>
<title></title>
</head>
<body>
<?php echo session_id();?>
<form method="post">
<input type="text" name="inpt" />
<input type="submit" value="frame2" />
</form>

Result:<br />
<?php
if(isset($data))
  echo session_id()."<hr>".$data;
?>
</body>
</html>
Martin Thorsen Ranang
  • 2,394
  • 1
  • 28
  • 43
tony007
  • 53
  • 1
  • 2
  • 5

1 Answers1

1

Default PHP session have blocking file-access. That means as long as in your first script the session is still active, the second script's access to the session is blocked. PHP will wait until the session is accessible again.

The solution often is to keep the time-span short for the active period. Normally the sessions does not need to be active all the time.

You activate a session with session_start().

You deactivate a session with session_commit().

Locate the part of your script where you actually need an active session. Open it as late as possible (start) and close (commit) it as soon as possible.

hakre
  • 193,403
  • 52
  • 435
  • 836