我希望我的 Web服务器在另一台TCP服务器上发生事件时通过php页面通知我,PHP服务器已经通过套接字成功连接了。事件就像TCP服务器想要向Web服务器发送消息等。有没有办法完成此操作和/或任何有关如何执行此操作的参考?
答案 0 :(得分:2)
不确定
$fp = fsockopen("tcp://example.com", 8888) OR die("could not connect");
while (!feof($fp)) {
$pc = fread($handle, 8192);
if ($pc === false || strlen($pc) == 0)
break;
//a new packet has arrived
//you should collect the read in a variable and wait
//for another packet until you know the message is complete
//(depends on the protocol)
collect_in_result($pc);
if (message_is_complete()) {
if (check_event()) {
//take action
}
}
}