tomcat重启后无法访问php会话变量
我正在用java开发一个应用程序,需要在tomcat服务器下集成一些php文件。我做的一切都成功了,但问题是,当我关闭 tomcat 服务器时,它会显示一些错误,例如
Exception in thread "JavaBridgeSessionTimer" java.lang.NullPointerException
at php.java.bridge.SessionFactory$SessionTimer.run(SessionFactory.java:157)
at java.lang.Thread.run(Thread.java:619)
稍后如果我再次启动,我无法从 php 文件访问任何会话变量。我尝试了一个在 tomcat 中运行的简单 php 程序。一旦我重新启动机器,这个问题就会得到解决,但我不想频繁地对tomcat中的任何配置文件进行任何更改。
会话1.php
<?php
session_start();
?>
<body><html>
<form action="session2.php" method="post">
<?php $_SESSION['name']="MyName"; ?>
<input type="submit" value="Submit">
</form>
</body>
会话2.php
<?php
session_start();
?>
<html>
<body>
<?php echo( $_SESSION['name'] ); ?>
</body>
</html>
I am developing an applicaton in java which needs to integrate some php files under tomcat server. I did everything successful, but the problem is that when i shutdown tomcat server it shows some error like
Exception in thread "JavaBridgeSessionTimer" java.lang.NullPointerException
at php.java.bridge.SessionFactory$SessionTimer.run(SessionFactory.java:157)
at java.lang.Thread.run(Thread.java:619)
Later if I start again I could not access any of the session variables from php files. I tried a simple php program which run within tomcat. This problem will get resolved once I restart the machine, but i don't want to do this frequently for any change in any configuration files in tomcat.
session1.php
<?php
session_start();
?>
<body><html>
<form action="session2.php" method="post">
<?php $_SESSION['name']="MyName"; ?>
<input type="submit" value="Submit">
</form>
</body>
session2.php
<?php
session_start();
?>
<html>
<body>
<?php echo( $_SESSION['name'] ); ?>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PHP 会话变量保存在内存中。这意味着如果您关闭服务器,它们就会丢失。
如果您需要它们在服务器重新启动后仍然保留,则需要将它们存储在数据库或类似的数据库中。
PHP session variables are held in memory. That means they are lost if you shut down the server.
If you need them to persist regardless of server restarts, you'll need to store them in a database or similar.