php - 从另一个脚本访问已经实例化的类的属性而无需重新实例化的任何方法?

0 php class instantiation

我有页面main.html,它是特定服务器的客户端应用程序.main.php是一个有三个框架的窗口.

main.html中

<frameset frameborder=no border=0>
 <frame name='top1' src='top1.php' frameborder=no scrolling=no>
        <frame name='top2' src='top2.php' frameborder=no scrolling=no>
 <frame name='firstpage' src='firstpage.php' frameborder=no scrolling=auto>
</frameset>
Run Code Online (Sandbox Code Playgroud)

firstpage.php

<?php 
....
....
require_once("connection.php");
// connection.php is a class which opens a socket and establishes with another server.
set_time_limit(0);
ignore_user_abort();

function parse($line) {
//parses $line returns $a which contains some data etc
....
return $a;
}

$connect= new Connection();
.....
$line=$connect->socket_read(1028);
.....
while ($i<200) {
$GLOBALS[userdata][$i]=parse($line);
.......
}
?>
Run Code Online (Sandbox Code Playgroud)

firstpage.php是一个大脚本,我已经修剪了firstpage.php的大部分,原因是易读性.connect.php和firstpage.php正如我想要的那样工作.

我需要在top1.php和top2中使用$ GLOBALS [userdata]进行进一步处理.无论如何我可以访问$ GLOBALS [userdata]而不再实例化connect.php吗?(我希望在top1.php和top2.php中进行的数据处理不能在firstpage.php中完成,原因我在这里无法讨论.)我无法重新实现connect.php,因为从服务器到firstpage.php的数据将会不要被我的服务器重新发送.

我已经意识到,因为firstpage.php无限运行$ GLOBALS没有写入.在$ GLOBALS [userdata] [$ i] = parse($ line)之后立即尝试session_write_close; 在while循环中.但那并没有帮助.

我还发现top1.php,top2.php和firstpage.php中的SESSIONID是相同的.

谁能指出我正确的方向?

谢谢!!

Eri*_*lje 5

页面作为完全独立的请求处理,因此您无法在传统意义上共享它们之间的数据.

理论上可以使用会话来完成它,因为所有页面都将作为同一会话的一部分加载.但是,它们的加载顺序并不完全可预测,因此您无法确定在加载另一个页面时已完成一个页面.所以在实践中,这可能也行不通.

框架导致问题的又一个原因..