【问题标题】:session_start problems when run process in parallel并行运行进程时的 session_start 问题
【发布时间】:2012-10-17 17:37:48
【问题描述】:

我需要两个 iframe 表单独立工作(异步),但是当我同时提交两个表单时,第二个 iframe 报告“致命错误:C:\wamp\www\iframe2.php 中超过 30 秒的最大执行时间在第 2 行”(当 iframe1 查询是一个长进程时)或第二个 iframe 在第一个进程完成后返回数据(当 iframe1 查询是一个短进程时)。 现在,我需要保留会话以验证用户登录。 我需要你的帮助,我的朋友们!谢谢

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>

【问题讨论】:

  • 为什么iframe2.php 中没有set_time_limit(120);

标签: php session iframe asynchronous locked


【解决方案1】:

默认 PHP 会话具有阻止文件访问。这意味着只要在您的第一个脚本中会话仍然活动,第二个脚本对会话的访问就会被阻止。 PHP 将等待会话再次可访问。

解决方案通常是在活动期间保持较短的时间跨度。通常会话不需要一直处于活动状态。

您使用session_start() 激活会话。

您停用了与session_commit() 的会话。

找到脚本中您实际需要活动会话的部分。尽可能晚地打开(开始)并尽快关闭(提交)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    相关资源
    最近更新 更多