2012-10-17 77 views
0

我需要這兩個iframe形成工作獨立(異步),但是當我同時提交兩個表單時,第二個iframe報告「致命錯誤:最大執行時間超過30秒C:\第二行加上wamp \ www \ iframe2.php(當iframe1查詢是一個很長的進程時),或者第二個iframe在第一個進程完成後返回數據(當iframe1查詢是一個短進程時)。 現在,我需要保持會話以驗證用戶登錄。 我需要你的幫助,我的朋友們!感謝session_start問題當並行運行進程

的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(返回查詢結果)

<?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(只返回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> 
+0

爲什麼在'iframe2.php'中沒有'set_time_limit(120);'? – Orbling

回答

1

默認PHP會話阻塞文件訪問。這意味着只要您的第一個腳本中的會話仍然是活動,則會阻止第二個腳本訪問會話。 PHP將一直等到會話可以再次訪問。

解決方案通常是保持活動期的時間間隔短。通常,會話不需要始終處於活動狀態。

您使用session_start()激活會話。

您使用session_commit()停用會話。

找到您實際需要活動會話的腳本部分。儘快打開它(開始)並儘快關閉(提交)它。