如何杀死一个PHP会话? [英] How to kill a PHP session?
问题描述
此通用主题之前已经出现过,此处,
This general topic has come up before, here, here, here, and no doubt elsewhere on the internet as well. In my case, unlike these, the hang arises from a blocking socket that never gets a message, and perhaps that's why the solutions described there haven't worked for me. I'm developing in tandem a C++ app which communicates with the php script via a local socket connection, and when the C++ app crashes, it leaves the php script's socket waiting for a message that never comes. I've tried using session_destroy and session_unset (calling these first in a script before session_start) but they don't work; even quitting and restarting the browser doesn't help. I can only stop the session if I remove the session_start, reload the script and then end the session via the client. How can I kill the session without having to go through that?
我忘了提一下,我也尝试过将套接字超时
I forget to mention, I also tried to time the socket out with
socket_set_option($socket,0, SO_RCVTIMEO, array("sec"=>1, "usec"=>0));
但是我遇到了无效操作"错误,并且没有任何作用.
But I got an 'invalid operation' error, and it didn't work.
按照提示>设置手动超时在这里,效果很好.我仍然仍然不知道如何终止例如卡在一个无限循环中,但是哦.
Edit 2: Setting a manual timeout, following the tip here, worked well enough. I still don't know how to, in general, kill a session that's e.g. stuck in an infinite loop, but oh well.
推荐答案
也许您可以给套接字超时?例如 socket_select
具有超时参数.
Maybe you can give a timeout to the socket? e.g. socket_select
has a timeout parameter.
1000s
的超时值可能太高,因为apache可能已经终止了该进程(请参阅php.ini
中的max_execution_time
)
The value of 1000s
as timeout may be too high, because apache may have killed the process before (see max_execution_time
in php.ini
)
这篇关于如何杀死一个PHP会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!