简体   繁体   中英

Close a socket connection with PHP

I have a script that opens a port and allows socket communication between multiple connections (a simple flash chat-box). This script has had to take care of itself regarding how long to run for and when to close the port. My question is, in case this script gets caught in an infinite loop (or I otherwise lose control of it) what can I do to close the port?

To be clear on this, I am after a second php script that will force close the port the first script has opened (I can then put some check code into this script to stop executing if the socket has been closed).

I'm not aware of a way to do that. A socket exists within the instance it was created. If you create the socket and run the while(1) loop inside script "foo.php", as far as I know, there's no way for a separate execution of another script, say "bar.php" to access the socket created in foo.php and close it down. Typically, client-server applications rely on threading to achieve socket pooling and monitoring.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM